wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CONDITIONAL STATEMENTS

Total questions: 25

Worksheet time: 21mins

Name
Class
Date
1.

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

2.

WHILE 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

3.

In a Python program, what would be the ending value for y in the WHILE LOOP code?

a)

5

b)

51

c)

10

d)

3

4.

In a Python program, what would be the ending value of total in the WHILE LOOP code?

a)

0

b)

5

c)

2

d)

20

5.

In a Python program, what would be the increment value for the looping variable in the FOR LOOP code?

a)

15

b)

7

c)

10

d)

1

6.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
7.

What are the three main programming structures?

a)

Sequence, selection, iteration

b)

Structured, object-oriented, procedural

c)

Java, Python, Visual Basic

d)

Machine, assembly, high-level

8.

Write the line of code which initialize the counter variable

a)

x<20

b)

x=x+1

c)

name=input("Enter your name")

d)

x=0

9.

What will this code display?

a = 6

if a => 6:

print("pass")

else:

print("fail")

a)

pass

b)

fail

c)

nothing because there will be an error

d)

passfail

10.

What will this code print?

a)

access denied

b)

access granted

c)

error

d)

password

11.

What is the error in this code?

a)

incorrect variable name

b)

incorrect indentation

c)

incorrect speech marks

d)

incorrect loop

12.

In the above program if the value of 'x' is 23 and 'number' is 24, what will be the output?

a)

23 24

b)

23

c)

23

24

d)

3 4

13.
Choose the correct Python code.
if age is less than 20 and greater than equal or equal to 15 then
a)
if age <20 and age >=15:
b)
if age <20>=15 :
14.

What would be outputted here?

a)

Bigger than 2!

b)

Number is 5

c)

Bigger than 2!

Number is 5

d)

Nothing

e)

Error

15.

What would be outputted here?

a)

it divides by 7!

b)

it divides by 3.

c)

It divides by 7!

d)

It divides by 3.

16.

What will be printed to the screen?

a)

Failure

b)

Part of the way there!

c)

Success

d)

Nothing

17.
What will the following lines of code print?
a)
A
b)
B C
c)
A B C
d)
Nothing, it will return an error.
18.
What is the result of running this code?
a)
You're living a good life!
b)
You're living a fantastic life!
c)
You're too young!
d)
The code runs with errors
19.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
20.

The program above prints

a)

Numbers between 1 and 100 that are multiples of 5

b)

Numbers between 1 and 100

c)

Numbers between 1 and 100 divisible by 5

d)

Numbers between 1 and 101 that are multiples of 5

21.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

22.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

23.

What does this program print

a)

2 + 2 = 4

4 + 4 = 8

8 + 8 = 16

16 + 16 = 32

32 + 32 = 64

b)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

c)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

2 + 10 = 12

d)

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

2 + 2 = 4

e)

2 + 2 = 4

2 + 4 = 6

2 + 6 = 8

2 + 8 = 10

24.
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)
25.

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