Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functions in Python

Total questions: 15

Worksheet time: 14mins

Name
Class
Date
1.

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

a)

Func

b)

define

c)

def

d)

function

2.

Which of the following pertains to a piece of code that can take inputs to perform a specific task?

a)

Arguments

b)

Functions

c)

Parameters

d)

Loops

3.

When defining a function, the definition must occur before it is called.

a)

TRUE

b)

FALSE

4.

The variable listed inside the parentheses in the function definition is called a(n) ​ (a)   , while the value that is sent to the function when it is called is a(n) ​ (b)   .

Choose from the below words
parameter
argument
5.

Which of the following describe what parameters are function? (Select 2)

a)

input value to a function for the function’s execution

b)

a variable used to send information to a function

c)

the name of the function

d)

the name of the main program calling the function

6.

Which of the following symbols always comes after a function code block?

a)

;

b)

]

c)

:

d)

#

7.

Which of the following is TRUE about the given function? (Select 3)

a)

checkOdd()checkOdd\left(\right) function will not run because it has 2 return values

b)

numnum is a parameter of the function checkOdd()checkOdd\left(\right)

c)

The value of numnum will determine the return value of the checkOdd()checkOdd\left(\right)

d)

The checkOdd()checkOdd\left(\right) function has two possible parameters.

e)

checkOdd()checkOdd\left(\right) will either return a True or False value.

8.

Parameters are the ​ (a)   used in the function definition.

Choose from the below words
variables
values
constant
method
9.

In Python, if no value is provided in the function call, the argument takes ​​ (a)   value.

Choose from the below words
default
provided
temporary
expounded
10.

Complete the syntax below to place on the "missing code" area on Line 4. The code must print the sum of 10 and 20:

​ (a)   (​ (b)   (​ (c)   , ​20))

Choose from the below words
print
mySum
10
def
return
11.

Complete the code block below to create a function with the function name as myFunction:

​ (a)   ​ (b)   ​ (c)   ​ (d)  

Choose from the below words
def
myFunction
()
:
func
void
{
12.

Fill-in the blanks on the syntax on Line 1 to output the phrase "Hello, Cedric."

def ​ (a)   (​ (b)   ):

Choose from the below words
myName
name
Cedric
Name
my_Name
13.

Complete the code on the attached image by dragging the handlers below to appropriate areas given below. The desired output is 7.

Line 2: ​ (a)   a+b

Line 4: ​ (b)   = 4

Line 6: print(​ (c)   (num1, ​ (d)   ))

Choose from the below words
return
num1
mySum
num2
14.

Complete the syntax below to create a Python Function with name "factorial" and parameter num.

​ (a)   ​ (b)   (​ (c)   ):

Choose from the below words
def
factorial
num
15.

The function checkOdd() determines if a given number is odd or even by returning True or False, respectively. Complete the code on the image by dragging and dropping the handlers to the correct spots below. The desired output is to display "a is an odd number" if it is odd, and "a is an even number" if otherwise.

Line 3: return ​ (a)  

Line 5: return ​ (b)  

Line 8: if(​ (c)   (​ (d)   )):

Choose from the below words
False
True
checkOdd
a