Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Functions and Ifs

Total questions: 20

Worksheet time: 58mins

Name
Class
Date
1.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
2.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
3.

What term is used to describe data passed into a function?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

4.

Leo wants to create a function that will roll a dice. Which is the correct function definition header?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []:

5.

Do you call or define a function first?

a)

call

b)

define

6.

Rewrite this line of code correctly!

(a)  

7.

Rewrite this line of code correctly!

(a)  

8.

What is a return in a function?

a)

Keyword that tells the function what to print

b)

Keyword that tells the function what value to send back

c)

Keyword that tells the function what to add

d)

Keyword that tells the function what parameter to pass

9.

What are the reasons for using functions? Select all that apply.

a)

To build code that will be reused

b)

To simplify code

c)

To add comments

d)

To help organize longer programs

10.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

11.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)

square(5)

12.

What is the syntax for defining a user defined function in Python?

a)

def function_name(parameters):

b)

function_name(parameters)

c)

function_name:

d)

function_name(parameters):

13.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
14.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

15.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

16.

What does the = = symbol mean in Python?

a)

Equal to or shows equality

b)

Not Equal

c)

Code that will be skipped

d)

End of clause

17.

What is the output?

a)

True

b)

False

c)

condition1

d)

condition2

18.

What will this program output?

a)

:(

b)

":("

c)

Error

d)

nothing

19.

What would be outputted here?

a)

it divides by 7!

b)

it divides by 3.

c)

It divides by 7!

d)

It divides by 3.

20.

What is the output of the code? Remember that integers and strings are different

a)

"String"

b)

"No string"

c)

18

d)

none of the above