wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Functions

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

What is the default return value for a function that does not return a value explicitly?

a)

None

b)

int

c)

double

d)

null

2.

Which of the following items are present in the function header?

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

3.

Which of the following keywords marks the begining of the function block?

a)

Func

b)

define

c)

def

d)

function

4.

What is the name given to that area of memory, where the system stores the parameters and local variables of a function call?

a)

a heap

b)

storage area

c)

a stack

d)

an array

5.

What Is The Output Of The Following Code Snippet?


def func(message, num = 1):

print(message * num)


func('Welcome')

func('Viewers', 3)

a)

Welcome

Viewers

b)

Welcome

ViewersViewersViewers

c)

Welcome

Viewers,Viewers,Viewers

d)

Welcome

6.

Which is the most appropriate definition for recursion?

a)

A function that calls itself

b)

A function execution instance that calls another execution instance of the same function

c)

A class method that calls another class method

d)

An in-built method that is automatically called

7.

Fill in the line of code for calculating the factorial of a number.


def fact(num):

if num == 0:

return 1

else:

return _____________________

a)

num*fact(num-1)

b)

(num-1)*(num-2)

c)

num*(num-1)

d)

fact(num)*fact(num-1)

8.

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))

a)

13

b)

7

c)

Infinite Loop

d)

17

9.

What happens if the base condition isn’t defined in recursive programs?

a)

Program gets into an infinite loop

b)

Program runs once

c)

Program runs n number of times where n is the argument given to the function

d)

An exception is thrown

10.

Which of the following function calls can be used to invoke the below function definition?


def test(a,b,c,d)

a)

test(1,2,3,4)

b)

test(a=1,2,3,4)

c)

test(a=1,b=2,c=3,4)

d)

test(a=1,b=2,c=3,d=4)

11.

what is a variable defined outside all the function referred to as?

a)

A static variable

b)

A global variable

c)

A local variable

d)

An automatic variable

12.

what is a variable defined inside all the function referred to as?

a)

A static variable

b)

A global variable

c)

A local variable

d)

An automatic variable

13.

What is the order of resolving scope of a name in a python program?

a)

B E G L

b)

G E B L

c)

L E G B

d)

L B E G

14.

Which of the given argument types can be skipped from a function call?

a)

Positional arguments

b)

keyword arguments

c)

named arguments

d)

default arguments

15.

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))

a)

return "number"

b)

print(number)

c)

print("number")

d)

return number