wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python procedures and functions

Total questions: 35

Worksheet time: 20mins

Name
Class
Date
1.

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 []:

2.

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

3.

What would the output be from this program?

a)

Error

b)

Hello

c)

Hello, World

d)

World

4.

What is the difference between a procedure and a function?

a)

They are the same thing

b)

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

c)

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

d)

A function can run without being called

5.

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

a)

Nothing

b)

Hello, world

c)

It will generate an error

6.

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

7.

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

a)

10

b)

14

c)

16

d)

error

8.
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
9.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
10.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
11.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
12.
Code executed based on a condition being true
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
13.
Code repeated / looped until a condition has been met or a set number of times.
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
14.
If you want more than one option for your code, what do you use (after if)?
a)
elif
b)
else
c)
ifif
15.
What will print?
a)
1 2
b)
1
c)
3
d)
5
16.

What is the term for the variables declared in the brackets of a function. eg

def setArea(radius):

What would be the term for radius?

a)

Parameter

b)

Argument

c)

Global variable

d)

function

17.

What is the term for the values passed into the function or procedure?

setArea(r)

What would be the term for r?

a)

Parameter

b)

Argument

c)

Global variable

d)

function

18.

A count controlled loop will..

a)

Repeat code until a condition is met

b)

Repeat code a specific amount of times

c)

Repeat code a random amount of times

d)

None of the above

19.

Which of these is NOT a loop in python?

a)

for loop

b)

while loop

c)

nested loop

d)

if loop

20.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

21.

What will be the output of this code?

a)

1,2,3,4,5,6,7,8,9,10,11,12

b)

0,2,4,6,8,10

c)

2,4,6,8,10,12

d)

2,4,6,8,10

22.

Which of these will allow me to count from 0-20 in steps of 5?

a)

for x in range(0,20):

print(x)

b)

while x = (0,20,5):

print(x)

c)

for x in range(0,21,5):

print(x)

d)

for x in range(0,21,5):

print(y)

23.

If i want to continuously check for a correct answer, what loop would i use?

a)

for loop

b)

while loop

24.
Which python operator means 'less than or equal to'?
a)
>
b)
<
c)
>=
d)
<=
25.
What is another word for 'iteration'?
a)
Selection
b)
Variable Assignment
c)
Repetition
d)
Sequencing
26.
How many times will this loop run?
a)
10
b)
9
c)
4
d)
5
27.
I want to allow the program to repeatedly ask the user to enter their guess if it does not equal the answer...Which option do I use?
a)
while guess == answer:
    guess=input()
b)
while answer != guess:
guess=input()
c)
while answer =! guess:
guess=input()
d)
while guess != answer:
guess=input()
28.

Which word completes this sentence: "Iteration makes code more ___________"

a)

Complex

b)

Efficient

c)

Simple

d)

Straightforward

29.

What will the output be for the code shown here?

a)

3,2,1,0

b)

0,1,2,3

c)

3,2,1

d)

1,2,3

30.

Anil is writing a "rock, scissors, paper" program. He wants the game to repeat until the user doesn't want to play anymore. What loop should he use?

a)

a FOR loop

b)

a WHILE loop

31.

Tara has written a "Hide and Seek Simulator" - what will happen when she runs it?

a)

It will print "1,2,3,4,5,6,7,8,9,10 Coming ready or not!"

b)

The program will not run

c)

It will print "1,2,3,4,5,6,7,8,9,11 Coming ready or not!"

d)

It will print ("10 Coming ready or not!")

32.
a)
12  9  6  3  0
b)
0  3  6  9  12
c)
9  6  3  0
d)
0  3  6  9
33.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
34.
a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
35.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)