What does this Python code print?
x = 5x = x + 2print(x)
Use this free practice quiz with 20 questions to review 4 Control Flow and Logic, test your knowledge, and prepare for your next test or exam.
What does this Python code print?
x = 5x = x + 2print(x)
5
7
10
2
True or false: In Python, a for loop can process each item in a list in order.
True
False
Which Python keyword immediately exits the nearest loop?
Complete the statement: In Python, is true only when both expressions are true.
What value is assigned to grade?
score = 85if score >= 90: grade = "A"elif score >= 80: grade = "B"else: grade = "C"
A
C
B
D
Select all values printed by this Python code.
for number in range(1, 6):
if number % 2 == 0:
continue
print(number)
1
2
3
4
5
True or false: A Python while loop tests its condition before each iteration.
True
False
How many pairs does this nested loop print?
for row in range(1, 3): for column in range(1, 4): print(row, column)
Complete the description of Python's range(1, 5): it starts at and excludes .
Which items are normally recorded when tracing a program? Select all correct choices.
Variable values
Condition results
Every possible input
Loop iterations
Output order
Why can this condition avoid division by zero?
denominator != 0 and numerator / denominator > 1
It converts the quotient to an integer.
It can prevent the division from being evaluated.
It reverses the result of the comparison.
It repeats the division until it succeeds.
Trace this program and state its final output. Explain how the value of total changes on each iteration.
total = 0for number in range(1, 5): if number % 2 == 0: total = total + numberprint(total)
Which sequence is printed by this Python code?
for number in range(1, 10):
if number == 5:
break
print(number)
1, 2, 3, 4, 5
2, 3, 4, 5
1, 2, 3, 4
5 only
True or false: If an outer loop runs 3 times and an inner loop runs 4 times for each outer iteration, the inner statement executes 12 times.
True
False
What value does this Python code print?
x = 5
x = x + 2
print(x)
5
7
10
3
What value is printed by this Python code?
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "D"
print(grade)
A
B
C
D
Which Python logical operator can prevent numerator / denominator > 1 from being evaluated when denominator is zero in this condition?
denominator != 0 and numerator / denominator > 1
or
not
and
==
Which sequence is printed by this Python loop?
for number in range(2, 6):
print(number)
2, 3, 4, 5, 6
2, 3, 4, 5
1, 2, 3, 4, 5
3, 4, 5, 6
Which Python keyword skips the rest of the current loop iteration and begins the next iteration?
What final value is printed?
total = 0
for number in range(1, 5):
if number % 2 != 0:
total = total + number
print(total)