WorksheetsPython Functions
Total questions: 15
Worksheet time: 15mins
What is the default return value for a function that does not return a value explicitly?
None
int
double
null
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
Which of the following keywords marks the begining of the function block?
Func
define
def
function
What is the name given to that area of memory, where the system stores the parameters and local variables of a function call?
a heap
storage area
a stack
an array
What Is The Output Of The Following Code Snippet?
def func(message, num = 1):
print(message * num)
func('Welcome')
func('Viewers', 3)
Welcome
Viewers
Welcome
ViewersViewersViewers
Welcome
Viewers,Viewers,Viewers
Welcome
Which is the most appropriate definition for recursion?
A function that calls itself
A function execution instance that calls another execution instance of the same function
A class method that calls another class method
An in-built method that is automatically called
Fill in the line of code for calculating the factorial of a number.
def fact(num):
if num == 0:
return 1
else:
return _____________________
num*fact(num-1)
(num-1)*(num-2)
num*(num-1)
fact(num)*fact(num-1)
What is the output of the following piece of code?
def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
13
7
Infinite Loop
17
What happens if the base condition isn’t defined in recursive programs?
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
An exception is thrown
Which of the following function calls can be used to invoke the below function definition?
def test(a,b,c,d)
test(1,2,3,4)
test(a=1,2,3,4)
test(a=1,b=2,c=3,4)
test(a=1,b=2,c=3,d=4)
what is a variable defined outside all the function referred to as?
A static variable
A global variable
A local variable
An automatic variable
what is a variable defined inside all the function referred to as?
A static variable
A global variable
A local variable
An automatic variable
What is the order of resolving scope of a name in a python program?
B E G L
G E B L
L E G B
L B E G
Which of the given argument types can be skipped from a function call?
Positional arguments
keyword arguments
named arguments
default arguments
Pick one from the following statements to correctly complete the function body to get the output 5 in the given code snippet:
def f(number):
#missing function body
print(f(5))
return "number"
print(number)
print("number")
return number
