WorksheetsSkill #2 - Flow Control with Decisions and Loops
Total questions: 10
Worksheet time: 21mins
What is the output of the following code?
b or a = False
b or a True
b is True
b or a = True
We have the following variables and their values:
grade_a = 9.5
grade_b = 8.7
grade_c = 8
Select the true statement.
grade_c == int(grade_b)
int(grade_a) > math.ceil(grade_b)
grade_c < int(grade_b)
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?
continue
pass
break
for
while
Choose the code that has the following output:
S
*U
**P
***E
****R
*****A
******T
*******E
name = "SUPERATE"
i = 0
for letter in name:
print("*" * i+letter)
i+=1
name = "SUPERATE"
i = 0
for letter in name:
print("*" , i,letter)
i++
name = "SUPERATE"
i = 0
for letter in name:
print("*i" +letter)
name = "SUPER"
i = 1
for letter in name:
print("*" * i)
i+=1
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)
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)
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:
def medals(placement):
if placement == 2:
print("You won a Silver medal")
elif placement == 3:
print("You won a Bronze medal")
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)
What is the output of the following code:
0
5
6
7
1
5
6
7
0
5
6
1
5
6
0
5
6
1
5
6
2
5
6
0
5
6
7
1
5
6
7
2
5
6
7
What is the output of the following code?
Access Permitted
You shall not pass!!!
Syntax Error
