Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming: Functions and Procedures

Total questions: 12

Worksheet time: 11mins

Name
Class
Date
1.

Which of the following is an advantage of using local variables?

a)

They allow the variable to be used throughout the whole program

b)

They allow variable identifiers to be reused each time

c)

They are easier to program than global variables

d)

A wider range of data types can be used

2.

What term is used to describe data passed into/out of a program?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

3.

Leo wants to create a subroutine that will roll a dice. Which syntax is correct?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []:

4.

What would the output be from the program shown here? (assuming that the user enters "John" and "Smith"

a)

John

b)

Smith

c)

John Smith

d)

Error

5.

What would the output be from this program?

a)

Error

b)

Hello

c)

Hello, World

d)

World

6.

What is the difference between a subroutine and a function?

a)

They are the same thing

b)

A subroutine passes values back out to the program, a function does not

c)

A function passes values back out to the program, a subroutine does not

d)

A function can run without being called

7.

What will the output of this program be when it is run?

a)

Nothing

b)

Hello, world

c)

It will generate an error

8.

What will be the output of this program if the user enters "Han" and then "Solo"?

a)

An error

b)

Nothing

c)

first surname

d)

Han Solo

9.

Which of the following statements is not true?

a)

Functions/subroutines are examples of reusable code

b)

Functions and subroutines should always be used in programs

c)

Using functions/subroutines make it easier to "deconstruct" a problem into smaller pieces

d)

They can make programs easier to read and understand

10.

What would the output be for the following program if the user enters 4 and 6?

a)

10

b)

14

c)

16

d)

error

11.
Which of the following best describes the order in which these lines are processed in Python?
a)
4, 1, 2
b)
4, 2, 1
c)
1, 2, 3, 4
d)
3, 1, 2
12.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)