Free Practice Quiz Question List

4 Control Flow and Logic Online Quiz Questions

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.

20 questions
01
Choose one
1 point

What does this Python code print?

x = 5
x = x + 2
print(x)

  1. A

    5

  2. B

    7

  3. C

    10

  4. D

    2

02
True or false
1 point

True or false: In Python, a for loop can process each item in a list in order.

  1. A

    True

  2. B

    False

03
Written response
1 point

Which Python keyword immediately exits the nearest loop?

04
Fill in the blank
1 point

Complete the statement: In Python, is true only when both expressions are true.

05
Choose one
1 point

What value is assigned to grade?

score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
else:
grade = "C"

  1. A

    A

  2. B

    C

  3. C

    B

  4. D

    D

06
Choose all
1 point

Select all values printed by this Python code.

for number in range(1, 6):

if number % 2 == 0:

continue

print(number)

  1. A

    1

  2. B

    2

  3. C

    3

  4. D

    4

  5. E

    5

07
True or false
1 point

True or false: A Python while loop tests its condition before each iteration.

  1. A

    True

  2. B

    False

08
Written response
1 point

How many pairs does this nested loop print?

for row in range(1, 3):
for column in range(1, 4):
print(row, column)

09
Fill in the blank
1 point

Complete the description of Python's range(1, 5): it starts at and excludes .

10
Choose all
1 point

Which items are normally recorded when tracing a program? Select all correct choices.

  1. A

    Variable values

  2. B

    Condition results

  3. C

    Every possible input

  4. D

    Loop iterations

  5. E

    Output order

11
Choose one
1 point

Why can this condition avoid division by zero?

denominator != 0 and numerator / denominator > 1

  1. A

    It converts the quotient to an integer.

  2. B

    It can prevent the division from being evaluated.

  3. C

    It reverses the result of the comparison.

  4. D

    It repeats the division until it succeeds.

12
Open ended
1 point

Trace this program and state its final output. Explain how the value of total changes on each iteration.

total = 0
for number in range(1, 5):
if number % 2 == 0:
total = total + number
print(total)

13
Choose one
1 point

Which sequence is printed by this Python code?

for number in range(1, 10):

if number == 5:

break

print(number)

  1. A

    1, 2, 3, 4, 5

  2. B

    2, 3, 4, 5

  3. C

    1, 2, 3, 4

  4. D

    5 only

14
True or false
1 point

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.

  1. A

    True

  2. B

    False

15
Choose one
1 point

What value does this Python code print?

x = 5

x = x + 2

print(x)

  1. A

    5

  2. B

    7

  3. C

    10

  4. D

    3

16
Choose one
1 point

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)

  1. A

    A

  2. B

    B

  3. C

    C

  4. D

    D

17
Choose one
1 point

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

  1. A

    or

  2. B

    not

  3. C

    and

  4. D

    ==

18
Choose one
1 point

Which sequence is printed by this Python loop?

for number in range(2, 6):

print(number)

  1. A

    2, 3, 4, 5, 6

  2. B

    2, 3, 4, 5

  3. C

    1, 2, 3, 4, 5

  4. D

    3, 4, 5, 6

19
Written response
1 point

Which Python keyword skips the rest of the current loop iteration and begins the next iteration?

20
Written response
1 point

What final value is printed?

total = 0

for number in range(1, 5):

if number % 2 != 0:

total = total + number

print(total)