Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CP M.7 Functions Assessment Review

Total questions: 20

Worksheet time: 18mins

Name
Class
Date
1.

Why do we use functions?

a)

To stop the program from repeating.

b)

To test for true and false.

c)

To simplify code.

d)

To ask the user for input.

2.

The _____________ go above the _____________ in the source code file

a)

main program, return

b)

main program, functions

c)

subprograms, main program

d)

def, functions

3.

Does the following code return a string or a number?

def f():

return "3"

a)

string

b)

number

4.

It is necessary to do something to the value returned by a function; otherwise the value will not be stored in memory and will be lost.

a)

True

b)

False

5.

A variable used to send information to a function.

a)

return

b)

Parameter

c)

Tracing code

d)

def

6.

We call the central part of the program the ______________ program

a)

main

b)

def

c)

sub

d)

return

7.

Which of the following parameters is optional?

sample ( a, b, c, d = 121)

a)

a

b)

d

c)

c

d)

b

8.

Consider the following code:

def tryIt (an):

val = an * 2

c = 0

if (val < 0):

c = 1

return c

Which variable is the parameter?

(a)  

9.

We (a)   to separate the code in functions from the main code.

10.

Consider the following code:

def addIt (a, b):

return a + b

print (a)

What is wrong?

a)

There should be a third parameter.

b)

The method cannot return a value.

c)

The method should only have one parameter.

d)

The print statement cannot be reached.

11.

Consider the following code:

def sub1 (a, b):

return(a + b)

def sub2 (a, b):

return(a * b)

What is output by:

print (sub2(sub1 (2, 3), (sub1(1, 1))))

(a)  

12.

Reading through code to find errors and predict results is called (a)   .

13.

What is output by the following program?

def mult(a, b = 1, c = 1):

return(a b c)

print(mult(2, 5, 6))

a)

0

b)

60

c)

2

d)

10

14.

Functions can do all of the following except:

a)

Stop the program from repeating.

b)

Allow writing without proper syntax.

c)

Simplify code.

d)

Ask the user for input.

15.

Which keyword is used in functions?

a)

send

b)

stop

c)

go

d)

return

16.

Consider the following program:

def sample(val):

val = val - 9

#MAIN

n = 59

sample(n)

print(n)

What is output?

a)

9

b)

50

c)

59

d)

n

17.

Consider the following code?

def mystery (a, b = 8, c = -6):

return a + b + c

#MAIN

x = int(input("First value: "))

y = int(input("Second value: "))

z = int(input("Third value: "))

print(mystery (x, y, z))

What is output when the user enters 12, 2 and 2?

a)

8

b)

14

c)

16

d)

0

18.

Which of the following parameters is optional?

sample(a, b, c = “Latte”)

a)

a

b)

b

c)

c

d)

none are optional

19.

What is output by the following program?

def test():

print("Rainbow")

#MAIN

test()

print("Sunshine")

print("Storm.")

a)

Sunshine Storm. Rainbow

b)

Rainbow Sunshine Storm.

c)

Storm. Sunshine Rainbow

d)

print("Rainbow") Sunshine Storm

20.

What is output by the following program?

def mult(a, b = 1, c = 1):

return(a b c)

print(mult(2, 5, 8))

a)

0

b)

80

c)

2

d)

10