Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functions With Return Values U1M2 Python

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

Function names cannot begin with a number as the first character.

a)

True

b)

False

2.

def showName():

print("Tobias Ledford")

Which code below calls the function in the above code?

a)

showName.run()

b)

open(showName)

c)

run showName

d)

showName()

3.

A function with 2 integer parameters could start with which definition?

a)

funct addNumbers(num1, num2):

b)

def addNumbers(num1, num2):

c)

def 2Numbers(num1, num2):

d)

FUNCTION addNumbers(x, y):

4.

def addNum(num1 = 10):

print(num1 + num1)


Choose the correct output of calling the above function using the following code:


addNum()

a)

0

b)

10

c)

20

d)

An Error

5.

Python Function return values must be stored in variables.

a)

True

b)

False

6.

def addNum(num1 = 10):

return num1 + num1


Choose the correct output of calling the function above using the following code:


print(addNum(100))

a)

20

b)

100

c)

200

d)

an error

7.

def addNumbers(num1, num2 = 10):

return num1 + num2


Choose the correct output of calling the function above using the following code:


print(addNumbers(100))

a)

100

b)

110

c)

200

d)

An Error

8.

def lowCase(wordsIn):

return wordsIn.lower()


Choose the correct output of calling the function above using the following code:


wordsLower = lowCase("Return THIS lower")

print(wordsLower)

a)

"Return THIS lower"

b)

No Output

c)

"return this lower"

d)

An Error

9.

Function calls should be placed at the beginning of a code page, and functions should be placed later and toward the end of the code.

a)

True

b)

False

10.

1.name = input("enter your name")

2. print(name, "your score is", score)

3. score = 199

Order the above numbered code lines into the proper sequence.

a)

1,2,3

b)

2,3,1

c)

3,1,2

d)

3,2,1

11.

1.

2. score = add_score(190)

3.

4. print(name, "your score is", score)

5.

At which line above should the following add_score() function definition be inserted so the program runs without error?


def add_score(current):

return current + 10

a)

line 1

b)

line 3

c)

line 5

d)

any of the above

12.

1. greet(name)

2. name = input("enter your name: ")

3. greet(name)

4. def greet(person): u

5. print("Hi,", person)

6. greet(name)


Which line or lines need to be removed from the above code so the program prints a greeting without error?

a)

lines 1 and 2

b)

lines 1 and 3

c)

line 1 only

d)

line 3 only