wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Review

Total questions: 81

Worksheet time: 1hrs 7mins

Name
Class
Date
1.

Look at the following code, what will it generate

a)

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

b)

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

c)

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

d)

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

2.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

3.
a)
b)
c)
d)

1,2,3,4

4.

#What is the output?

a)

1,2,3,4,5

b)

0,1,2,3,4

c)

1,2,3,4

d)

5,4,3,2,1

5.

#How many hallos will be printed?

a)

5

b)

None

c)

4

d)

6

6.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
7.
What is iteration known as?
a)
Looping
b)
Crashing
c)
Repeating
8.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
9.

Which of the following programs prints ten lines?

a)

for i in range(10):

print("hi")

b)

for i = 1 to 10:

print("hi")

c)

for i in 1 - 10:

print("hi")

d)

for i from 0 to 9:

print("hi")

10.

What would be the output of the following code:

for i in range(3):

print(i)

a)

1 2 3

b)

i i i i

c)

i i i

d)

0 1 2

11.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4

12.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

13.

Which of these will allow me to print all numbers from 0 to 4 ?

//0,1,2,3,4

a)

for x in range(4):

print(x)

b)

for x in range(0,4):

print(x)

c)

for x in range(1,5):

print(x)

d)

for x in range(5):

print(x)

14.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

15.

For i in range(6):

print('Happy Python')

How many times Happy Python will be printed?

a)

4

b)

5

c)

6

d)

7

16.

What are the syntax errors in this code?

a)

:

b)

Not indented

c)

Both options

17.

What is the output of range(1,10)

a)

0123456789

b)

123456789

c)

1 to 10

d)

012345

18.

How many times does the following program print the word ‘computer’:

word= "computer"  

for num in range(2,8):

      print(word)

a)

5

b)

6

c)

1

d)

0

19.

For i in range(4):

print('Happy Python')

How many times Happy Python will be printed?

a)

4

b)

5

c)

6

d)

7

20.

What will be the output of this code?

a)

Hi

b)

3
Hi

c)

3

d)

Hi
Hi
Hi

21.

What will be the output of this code?

a)

2

b)

4

c)

6

d)

12

22.

What will be the output of this code?

a)

2

b)

4

c)

6

d)

12

23.

What will be the output of this code?

a)

1

b)

3

c)

4

d)

5

24.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

25.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
26.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

27.

Which kind of loop would be used?


I need a program that will keep letting me add money to a piggy bank until I get to £100.

a)

FOR Loop

b)

WHILE Loop

28.

Which kind of loop would be used?


I need a program that will keep letting me add a monthly payment for 12 months.

a)

FOR Loop

b)

WHILE Loop

29.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
30.
What is iteration known as?
a)
Looping
b)
Crashing
c)
Repeating
31.

numbers = [5, 14, 9, 17]

for number in numbers:

if number % 3 == 0:

print(number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

32.

numbers = [5, 14 ,9, 17]

for number in numbers:

if number >= 9:

print (number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

33.
Which of the following will print:
a)
for i in range(1, 5):   
print(str(i) * 5)
b)
for i in range(1, 5):   
print("i" * i)
c)
for i in range(1, 6):   
print("i" * i)
d)
for i in range(1, 6):   
print(str(i) * i)
34.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
35.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
36.

Which of the following programs prints ten lines?

a)

for i in range(10):

print("hi")

b)

for i = 1 to 10:

print("hi")

c)

for i in 1 - 10:

print("hi")

d)

for i from 0 to 9:

print("hi")

37.

Which of the following best describes the purpose of a for loop?

a)

A for loop is for doing something an indeterminate number of times.

b)

A for loop is doing something an infinite number of times.

c)

A for loop is for doing something a fixed number of times.

d)

A for loop is for doing something three times.

38.

Which of the following for loops would print the following numbers?

3

5

7

9

a)

for i in range(3, 10, 2):

print(i)

b)

for i in range(3, 9, 2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

39.

What is the value of num when this loop completes?


num = 0

for i in range(2, 8, 2):

num += i

a)

2

b)

8

c)

12

d)

20

40.

Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?

a)

for i in range(0, 5):

b)

for i in range(5):

c)

for i in range(0, 5, 1):

d)

for i in range(5, 0, 1):

41.

What would be the output of the following code:

for i in range(3):

print(i)

a)

1 2 3

b)

i i i i

c)

i i i

d)

0 1 2

42.

drink_choices = ["coffee", "tea", "water", "juice", "soda"]

for drink in drink_choices:

print(drink)

a)

"coffee"

b)

["coffee", "tea", "water", "juice", "soda"]

c)

drink

d)

"coffee tea water juice soda"

43.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4

44.

numbers = [2, 4, 6, 8]

for number in numbers:

print("hello!")

a)

2 hello! 4 hello! 6 hello! 8 hello!

b)

hello!

c)

2 4 6 8

d)

hello! hello! hello! hello!

45.

What will be the output after the following statements?

a)

0

b)

1

c)

2

d)

15

e)

error

46.

What will be the output after the following statements?

a)

0

b)

1

c)

2

d)

15

e)

error

47.

What will be the output after the following statements?

a)

15

b)

yes

c)

equal

d)

no

e)

error

48.

What will be the output after the following statements?

a)

false

b)

true

c)

not false

d)

not true

e)

error

49.

What will be the output after the following statements?

a)

true

b)

not false

c)

false

d)

not true

e)

error

50.

What will be the output after the following statements?

a)

true

b)

not false

c)

false

d)

not true

e)

error

51.

What will be the output after the following statements?

a)

true

b)

not false

c)

false

d)

not true

e)

error

52.

What will be the output after the following statements?

a)

true

b)

not false

c)

false

d)

not true

e)

error

53.

What will be the output after the following statements?

a)

true

b)

not false

c)

false

d)

not true

e)

error

54.

What output will be produced by the following segment of code?

a)

Too Low

b)

Too High

c)

Syntax Error

d)

No Output - Logic Error

55.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
56.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

57.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

58.

True/False: The body of an "if" statement will only be executed if the condition is true.

a)

True

b)

False

59.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
60.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
61.

What is a Syntax Error?

a)

A problem with the language ("grammar") used

b)

A problem with the logical structure used

c)

A problem with the version of Python used

d)

A problem with the Operating System

62.

What is Syntax?

a)

Syntax is the word used to describe an error

b)

Syntax is the rules of the programming language

c)

It is used to read information

d)

It is used to output information

63.

When you have an error in your code what is the term used to define finding and fixing that error?

a)

Error checking

b)

Debugging

c)

Syntax finder

d)

Error finder

64.
Max has written this program in Python.
One of the lines contains at least one error.
Which line is it?
a)
Line 1
b)
Line 2
c)
Line 3
d)
Line 4
65.
This operator means that one value is the same as the other value
a)
==
b)
!=
c)
>
d)
<
66.
This operator means that one value is not equal to another value
a)
==
b)
<=
c)
>=
d)
!=
67.

The result of this program:

Friday = False

if Friday:

print "Jeans day!"

else:

print "Uniform day"

a)

Jeans day

b)

Today is Friday

c)

Uniform day

d)

Not Friday

68.

What is the output?

a)

condition

b)

True

c)

Program has a syntax error.

d)

3 > 2

69.

What is the output?

a)

True

b)

False

c)

condition1

d)

condition2

70.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

71.

What is the output?

a)

250.0

b)

200.0

c)

300.0

d)

350.0

72.

What is the output?

a)

next

stop

b)

next

c)

stop

d)

syntax error - program doesn't work

73.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

74.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

75.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

76.
Which of the following symbols is used in Python to mean "Not equal to"?
a)
==
b)
!=
c)
<>
d)
><
77.
Which of the following symbols is used in Python to mean "Greater than or equal to"?
a)
<=
b)
>>
c)
>=
d)
=>
78.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
79.
a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
80.

What will be the output for the following code?

i = 0

while i < 5:

print(i)

i = i + 1

a)

1 2 3 4 5

b)

0 1 2 3 4 5

c)

1 2 3 4

d)

0 1 2 3 4

81.

What is the output for the following code?

i = 9

while i > 0:

print("Hello")

a)

9

b)

0

c)

Infinite

d)

8