Free Practice Quiz Question List

04. Conditional Statements Online Quiz Questions

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

20 questions
01
Choose one
1 point

What does this valid Python code print?

age = 16

if age >= 18:

print("Adult")

else:

print("Minor")

  1. A

    It prints "Minor".

  2. B

    It prints "Adult".

  3. C

    It prints nothing.

  4. D

    It raises a syntax error.

02
Choose one
1 point

What value is assigned to grade when score = 85 in this valid Python chain?

if score >= 90:

grade = "A"

elif score >= 80:

grade = "B"

elif score >= 70:

grade = "C"

else:

grade = "F"

  1. A

    A

  2. B

    B

  3. C

    C

  4. D

    F

03
Choose one
1 point

What message is printed by this valid Python nested conditional when username = "" and password_correct = True?

if username != "":

if password_correct:

print("Login successful")

else:

print("Incorrect password")

else:

print("Username is required")

  1. A

    Login successful

  2. B

    Incorrect password

  3. C

    Username is required

  4. D

    No output

04
Choose all
1 point

Select all statements that are correct about Python Boolean expressions.

  1. A

    True and False evaluates to False.

  2. B

    True or False evaluates to False.

  3. C

    not False evaluates to True.

  4. D

    False and False evaluates to True.

05
Choose all
1 point

Which practices belong to the validation sequence described in the material? Select all that apply.

  1. A

    Check whether the input has the correct basic form.

  2. B

    Check whether the value is within the allowed range.

  3. C

    Always perform the dependent operation before validation.

  4. D

    Report an error or reject the input when a rule fails.

  5. E

    Continue only when the input is valid.

06
True or false
1 point

True or false: In Python, a single = is the correct operator for comparing two values in an if condition.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: In the material's classify_speed example, a speed of 30 is classified as Slow, while a speed of 31 is classified as Moderate.

  1. A

    True

  2. B

    False

08
Written response
1 point

Which Python keyword introduces the alternative branch in a two-way if-else decision?

09
Written response
1 point

Enter the Python keyword that means “else if” and adds another condition to a chained conditional.

10
Fill in the blank
1 point

Complete the statement: In Python, the punctuation mark after an if condition marks the beginning of the indented block.

11
Fill in the blank
1 point

Complete the statement: Inside a function, a guard clause often uses to handle an invalid or exceptional case immediately.

12
Open ended
1 point

Explain the recommended validation sequence for conditional logic and why an operation such as division should occur only after its relevant invalid case has been checked.

13
Choose one
1 point

What does classify_speed(60) return in the material's range-classification function?

  1. A

    Fast

  2. B

    Moderate

  3. C

    Slow

  4. D

    Invalid

14
True or false
1 point

True or false: In an if/elif chain, Python executes every branch whose condition is true.

  1. A

    True

  2. B

    False

15
Written response
1 point

In the validation pattern that handles an invalid or exceptional case immediately so the main operation is less deeply nested, what two-word pattern name is used?

16
Choose one
1 point

What is printed by this Python code?

items = []

if items:

print("Items found")

else:

print("No items")

  1. A

    Items found

  2. B

    No items

  3. C

    The list itself

  4. D

    An error occurs

17
Choose one
1 point

What value is assigned to status?

age = 16

status = "adult" if age >= 18 else "minor"

  1. A

    minor

  2. B

    adult

  3. C

    16

  4. D

    An error occurs

18
Choose one
1 point

What is the value of message after this code runs?

value = None

if value:

message = "present"

else:

message = "missing"

  1. A

    present

  2. B

    None

  3. C

    missing

  4. D

    The variable is unchanged

19
Choose one
1 point

A program should accept either "yes" or "y" as the value of choice. Which condition correctly tests both possibilities?

  1. A

    if choice == "yes" or "y":

  2. B

    if choice == ("yes" or "y"):

  3. C

    if choice in "yes", "y":

  4. D

    if choice == "yes" or choice == "y":

20
Written response
1 point

A program sets records = [] and then evaluates if records:. What Python Boolean value does the condition have?