wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 3 - Functions

Total questions: 26

Worksheet time: 16mins

Name
Class
Date
1.

Which type of function is provided by the Python language?

a)

Anonymous Functions

b)

User-defined Functions

c)

Object Functions

d)

Built-in functions

2.

Which of the following is NOT a valid function invocation?

a)

print("Bla")

b)

max(3; 4)

c)

pow(5, 6)

d)

input()

3.

Which of the following is NOT a valid function invocation?

a)

print "Bla"

b)

max(3, 4)

c)

len("ABC123")

d)

print()

4.

True or False:

When a function returns a value, we can use it as an argument to another function, like this:

max(1, pow(2, n))

a)

True

b)

False

5.

True or False:

Methods need to be called in reference to an object, like this:

leonardo.move_forward(10)

a)

True

b)

False

6.

Which is the correct way to invoke the "title" method on the string stored in variable "name".

a)

name(title())

b)

title.name()

c)

name.title()

d)

title(name())

7.

Which module provides functions for generating random values?

a)

random

b)

randint

c)

rand

d)

math

8.

Which function from the random module can be used to generate a random integer?

a)

random

b)

choice

c)

uniform

d)

randint

9.

Which function from the random module can be used to generate a random floating point number?

a)

random

b)

choice

c)

uniform

d)

randint

10.

Which function call will return a random value between (and including) 1 and 20?

a)

randint(0, 20)

b)

randint(1, 20)

c)

randint(0, 21)

d)

randint(1, 21)

11.

Which function call will return a random float between (and including) 1 and 20?

a)

uniform(1, 20)

b)

randint(1, 20)

c)

uniform(0, 21)

d)

randint(0, 21)

12.

Which function call will return a random value between (but not including) 1 and 20?

a)

randint(2, 19)

b)

randint(1, 20)

c)

randint(1, 19)

d)

randint(2, 20)

13.

Which keyword is used at the very beginning of a function definition?

a)

function

b)

define

c)

def

d)

func

14.

True or False:

The code stored inside of a function needs to be indented.

a)

True

b)

False

15.

Which of the following is the correct way to write the first line of the function definition for a function called "start_game"?

a)

def start_game

b)

def start_game ():

c)

def start_game ()

d)

def start_game:

16.

True or False:

If a function does not have any parameters, then you don't need the brackets on the line with "def".

a)

True

b)

False

17.

True or False:

You can only invoke a user-defined function once in your program.

a)

True

b)

False

18.

True or False:

It doesn't matter which order you put parameters in your function definition.

a)

True

b)

False

19.

Which of the following is the correct way to start defining a function called "calculate_area" that takes two arguments: the base an height of a triangle

a)
b)
c)
d)
20.

The function "welcome" is defined as in the picture. What will be printed when this is called:

welcome("Joe", "Smith")

a)

Hello Joe Smith

b)

Hello Smith Joe

c)

Hello Joe Joe

d)

Hello Smith Smith

21.

The function "welcome" is defined as in the picture. What will be printed when this is called:

welcome("Joe")

a)

Hello Joe

b)

Hello Joe Joe

c)

Hello Joe None

d)

*** ERROR ***

22.

When defining a function, what do we call the variables that are put in the brackets as placeholders for the arguments?

a)

arguments

b)

parameters

c)

inputs

d)

placeholders

23.

True or False:

A user-defined function must have parameters.

a)

True

b)

False

24.

The "calculate_area" function is defined in the picture.

What is the correct way to invoke (call) this function to find the area of a triangle with base length 8 and height 10?

a)

calculate_area(8, 10)

b)

calculate_area(8)(10)

c)

calculate_area(10, 8)

d)

calculate_area(10)(8)

25.

The "calculate_area" function is defined in the picture.

Which of the following is NOT a correct way to invoke (call) this function?

a)

calculate_area(1.2, 3.4)

b)

calculate_area(8, 10)

c)

calculate_area(12345, 98765)

d)

calculate_area(7.34; 9.12)

26.

Which type of function is created by the programmer for use later in the program.

a)

Anonymous Functions

b)

User-defined Functions

c)

Object Functions

d)

Built-in functions