Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Skill #2 - Flow Control with Decisions and Loops

Total questions: 10

Worksheet time: 21mins

Name
Class
Date
1.

What is the output of the following code?

a)

b or a = False

b)

b or a True

c)

b is True

d)

b or a = True

2.

We have the following variables and their values:

grade_a = 9.5

grade_b = 8.7

grade_c = 8

Select the true statement.

a)

grade_c == int(grade_b)

b)

int(grade_a) > math.ceil(grade_b)

c)

grade_c < int(grade_b)

3.

In Python there are certain keywords that are used in a loop.

One of them is used when one condition needs to be temporarily ignored.

Which one?

a)

continue

b)

pass

c)

break

d)

for

e)

while

4.

Choose the code that has the following output:

S

*U

**P

***E

****R

*****A

******T

*******E

a)

name = "SUPERATE"

i = 0

for letter in name:

print("*" * i+letter)

i+=1

b)

name = "SUPERATE"

i = 0

for letter in name:

print("*" , i,letter)

i++

c)

name = "SUPERATE"

i = 0

for letter in name:

print("*i" +letter)

d)

name = "SUPER"

i = 1

for letter in name:

print("*" * i)

i+=1

5.

​The myth says that a peasant beat a king in chess and as a prize he asked for wheat grains. One grain for the first chessboard square, 2 for the second and double the previous grains for each subsequent square. (64 squares in total) Your code need to output the amount of wheat grains for each chessboard square. Complete the code accordingly.

grains = 1

​ ​ (a)  

grains = 2 ** (square-1)

print("Square", square, "total grains =", grains)

Choose from the below words
for square in range(1,65):
for square in range(2,65):
for square in range(1,64):
while square < 65:
for square in range(64):
6.

We have an array of a part of the Fibonacci sequence. In a Fibonacci sequence every number after the first two is the sum of the two preceding ones. Unfortunately, we have mistankenly added a number not in the sequence. We want our code to print all the numbers in the array until it reaches the false number.

fib = [1,1,2,3,5,6,8,13,21]

print(fib[0])

print(fib[1])

pos = 2

​ (a)   (pos < len(fib)):

if fib[pos-2] + fib[pos-1] != fib[pos]:

​ (b)  

else:

print(fib[pos])

​ (c)  

Choose from the below words
while
break
pos += 1
for
pass
pos = 2
7.

We need to create a function to return a message to the first three finalists.

If they finished second the message would be You won a Silver medal.

If they finished third the message would be You won a Bronze medal.

Reorder the following:

a)

def medals(placement):

b)

if placement == 2:

c)

print("You won a Silver medal")

d)

elif placement == 3:

e)

print("You won a Bronze medal")

1)
2)
3)
4)
5)
8.

You want your code to check if your team's points are more than the other team's points. If they are then the message should say Way to go . If not the message Better luck next time should appear.​ Make sure that the lines of codes are in the correct order

. (a)  

​ (b)  

​ (c)  

​ (d)  

Choose from the below words
if our_points > their_points:
print("Way to go")
else:
print("Better luck next time")
elif:
9.

What is the output of the following code:

a)

0

5

6

7

1

5

6

7

b)

0

5

6

1

5

6

c)

0

5

6

1

5

6

2

5

6

d)

0

5

6

7

1

5

6

7

2

5

6

7

10.

What is the output of the following code?

a)

Access Permitted

b)

You shall not pass!!!

c)

Syntax Error