What happens when this Python code runs?
temperature = 72
if temperature > 80:
print("It is hot.")
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.
What happens when this Python code runs?
temperature = 72
if temperature > 80:
print("It is hot.")
It prints It is hot.
It prints nothing
It raises an error because 72 is too low
It changes temperature to 80
What does this code print?
number = 0
if number == 0:
print("Zero")
elif number >= 0:
print("Positive")
else:
print("Negative")
Positive
Negative
Zero
Nothing
Given items = ["pen", "notebook"], what is the result of the condition items and items[0] == "pen" in an if statement?
The condition is true
The condition is false
Python raises an IndexError before comparing the first item
Python skips the entire condition because and always short-circuits
Which two values below are treated as false in a Python conditional context? Select all that apply.
False
"hello"
None
[1]
42
Which three statements accurately describe the logical expressions used in Python conditional control flow? Select all that apply.
age >= 18 and has_id requires both conditions to be true
is_weekend or is_holiday can be true when either condition is true
not is_locked has the same truth value as is_locked
member and (balance > 0 or balance == 0) can be true when member is true and the balance is nonnegative
True or false: In Python, an elif clause is tested only after the preceding condition is false.
True
False
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.
True
False
What kind of operation does Python perform when it evaluates score == 100?
According to the material, how many spaces does Python conventionally use for each indentation level?
Complete the description: Use to test an additional condition, and use for a default action when no preceding condition is true.
Complete the sentence: A nonempty string is generally treated as in a Python conditional context.
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)
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")
You must be at least 18
A ticket is required
You may enter
Nothing
For age = 25, what is the result of the chained comparison 18 <= age < 65?
The condition is true
The condition is false
Python interprets it as (18 <= age) < 65, causing a type error
Python does not allow chained comparisons
Which Python keyword introduces an additional condition that is tested only if the preceding if condition is false?
Which condition follows the recommended Python practice for checking whether the variable value is the singleton None object?
value == None
value is None
value = None
value in None
A program should reject a password only when it appears in the list revoked_passwords. Which condition correctly identifies a revoked password?
if password in revoked_passwords:
if password not in revoked_passwords:
if password != revoked_passwords:
if password is not revoked_passwords:
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?
def process_order(order):
if order:
if order.is_paid:
return "Order processed"
return "Payment is required"
return "Order is empty"
def process_order(order):
if not order:
return "Order processed"
if not order.is_paid:
return "Payment is required"
return "Order is empty"
def process_order(order):
if not order:
return "Order is empty"
if not order.is_paid:
return "Payment is required"
return "Order processed"
def process_order(order):
if not order.is_paid:
return "Payment is required"
if not order:
return "Order is empty"
return "Order processed"
If name = "Ada" and names = ["Grace", "Linus"], the condition name not in names evaluates to True.
True
False
In a Python function that uses early validation, which keyword exits the function immediately after an invalid input is detected?
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.