Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON (Functions)

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which keyword is used for functions?

a)

func

b)

def

c)

define

d)

function

2.

What will be the output of this program?


def addOne(number):

number += 1

return number

one = addOne(0)

two = addOne(one)

print(two)

a)

0

b)

1

c)

2

d)

3

e)

4

3.

What will be the output of this program?


def hello():

print(“I am a beginner”)

hello()

hello()

a)

I am a beginner

b)

I am a beginner I am a beginner

c)

Hello

d)

Hello

Hello

e)

I am a beginner

I am a beginner

4.

When a variable is inside of a function what do you call its scope?

a)

Static

b)

Local

c)

Global

d)

Boolean

5.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger

6.

What is missing in the following code?


def sumA(count):

a = count+1

return a

print(a)

a)

The initialization of variable a

b)

A function call

c)

The declaration of the global variable a

d)

The print statement inside the function

7.

What is the output of this program?


def printmessage(message, ntimes = 1):

print(message * ntimes)

printmessage(“Hello”)

printmessage(“Hello”, 5)

a)

Hello

b)

Hello Hello 5

c)

Hello Hello

d)

Hello

HelloHelloHelloHelloHello

8.

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

a)

Int

b)

Float

c)

Double

d)

None

9.

What does the function header contain?

a)

The function name

b)

The function name and parameter list

c)

The parameter list

d)

The return value

10.

What is the output of this code?


num = 1

def func():

num = 4

print(num)

func()

print(num)

a)

1 1

b)

4 4

c)

4 1

d)

1 4