Free Practice Quiz Question List

3 Conditional Control Flow Online Quiz Questions

Use this free practice quiz with 20 questions to review 3 Conditional Control Flow, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What happens when this Python code runs?

temperature = 72

if temperature > 80:

print("It is hot.")

  1. A

    It prints It is hot.

  2. B

    It prints nothing

  3. C

    It raises an error because 72 is too low

  4. D

    It changes temperature to 80

02
Choose one
1 point

What does this code print?

number = 0

if number == 0:

print("Zero")

elif number >= 0:

print("Positive")

else:

print("Negative")

  1. A

    Positive

  2. B

    Negative

  3. C

    Zero

  4. D

    Nothing

03
Choose one
1 point

Given items = ["pen", "notebook"], what is the result of the condition items and items[0] == "pen" in an if statement?

  1. A

    The condition is true

  2. B

    The condition is false

  3. C

    Python raises an IndexError before comparing the first item

  4. D

    Python skips the entire condition because and always short-circuits

04
Choose all
1 point

Which two values below are treated as false in a Python conditional context? Select all that apply.

  1. A

    False

  2. B

    "hello"

  3. C

    None

  4. D

    [1]

  5. E

    42

05
Choose all
1 point

Which three statements accurately describe the logical expressions used in Python conditional control flow? Select all that apply.

  1. A

    age >= 18 and has_id requires both conditions to be true

  2. B

    is_weekend or is_holiday can be true when either condition is true

  3. C

    not is_locked has the same truth value as is_locked

  4. D

    member and (balance > 0 or balance == 0) can be true when member is true and the balance is nonnegative

06
True or false
1 point

True or false: In Python, an elif clause is tested only after the preceding condition is false.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: Python requires every conditional block to be indented by exactly four spaces, even when a different consistent indentation level is used throughout the block.

  1. A

    True

  2. B

    False

08
Written response
1 point

What kind of operation does Python perform when it evaluates score == 100?

09
Written response
1 point

According to the material, how many spaces does Python conventionally use for each indentation level?

10
Fill in the blank
1 point

Complete the description: Use to test an additional condition, and use for a default action when no preceding condition is true.

11
Fill in the blank
1 point

Complete the sentence: A nonempty string is generally treated as in a Python conditional context.

12
Open ended
1 point

Predict the output of this code and explain why the later branches do not execute:

score = 84

if score >= 90:

grade = "A"

elif score >= 80:

grade = "B"

elif score >= 70:

grade = "C"

else:

grade = "Needs improvement"

print(grade)

13
Choose one
1 point

What does this code print?

age = 21

has_ticket = False

if age >= 18:

if has_ticket:

print("You may enter")

else:

print("A ticket is required")

else:

print("You must be at least 18")

  1. A

    You must be at least 18

  2. B

    A ticket is required

  3. C

    You may enter

  4. D

    Nothing

14
Choose one
1 point

For age = 25, what is the result of the chained comparison 18 <= age < 65?

  1. A

    The condition is true

  2. B

    The condition is false

  3. C

    Python interprets it as (18 <= age) < 65, causing a type error

  4. D

    Python does not allow chained comparisons

15
Written response
1 point

Which Python keyword introduces an additional condition that is tested only if the preceding if condition is false?

16
Choose one
1 point

Which condition follows the recommended Python practice for checking whether the variable value is the singleton None object?

  1. A

    value == None

  2. B

    value is None

  3. C

    value = None

  4. D

    value in None

17
Choose one
1 point

A program should reject a password only when it appears in the list revoked_passwords. Which condition correctly identifies a revoked password?

  1. A

    if password in revoked_passwords:

  2. B

    if password not in revoked_passwords:

  3. C

    if password != revoked_passwords:

  4. D

    if password is not revoked_passwords:

18
Choose one
1 point

Which implementation correctly returns "Order is empty" for an empty order, "Payment is required" for an unpaid order, and "Order processed" otherwise while keeping the successful path minimally nested?

  1. A

    def process_order(order):

    if order:

    if order.is_paid:

    return "Order processed"

    return "Payment is required"

    return "Order is empty"

  2. B

    def process_order(order):

    if not order:

    return "Order processed"

    if not order.is_paid:

    return "Payment is required"

    return "Order is empty"

  3. C

    def process_order(order):

    if not order:

    return "Order is empty"

    if not order.is_paid:

    return "Payment is required"

    return "Order processed"

  4. D

    def process_order(order):

    if not order.is_paid:

    return "Payment is required"

    if not order:

    return "Order is empty"

    return "Order processed"

19
True or false
1 point

If name = "Ada" and names = ["Grace", "Linus"], the condition name not in names evaluates to True.

  1. A

    True

  2. B

    False

20
Written response
1 point

In a Python function that uses early validation, which keyword exits the function immediately after an invalid input is detected?