WorksheetsPYTHON (Functions)
Total questions: 10
Worksheet time: 5mins
Which keyword is used for functions?
func
def
define
function
What will be the output of this program?
def addOne(number):
number += 1
return number
one = addOne(0)
two = addOne(one)
print(two)
0
1
2
3
4
What will be the output of this program?
def hello():
print(“I am a beginner”)
hello()
hello()
I am a beginner
I am a beginner I am a beginner
Hello
Hello
Hello
I am a beginner
I am a beginner
When a variable is inside of a function what do you call its scope?
Static
Local
Global
Boolean
What is the purpose of a function?
They are reusable pieces of programs.
They are required by the Python
They allow us to compile our program
They make the program larger
What is missing in the following code?
def sumA(count):
a = count+1
return a
print(a)
The initialization of variable a
A function call
The declaration of the global variable a
The print statement inside the function
What is the output of this program?
def printmessage(message, ntimes = 1):
print(message * ntimes)
printmessage(“Hello”)
printmessage(“Hello”, 5)
Hello
Hello Hello 5
Hello Hello
Hello
HelloHelloHelloHelloHello
What is the default return value of a function that does not return any value explicitly?
Int
Float
Double
None
What does the function header contain?
The function name
The function name and parameter list
The parameter list
The return value
What is the output of this code?
num = 1
def func():
num = 4
print(num)
func()
print(num)
1 1
4 4
4 1
1 4
