What does this valid Python code print?
age = 16
if age >= 18:
print("Adult")
else:
print("Minor")
Use this free practice quiz with 20 questions to review 04. Conditional Statements, test your knowledge, and prepare for your next test or exam.
What does this valid Python code print?
age = 16
if age >= 18:
print("Adult")
else:
print("Minor")
It prints "Minor".
It prints "Adult".
It prints nothing.
It raises a syntax error.
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"
A
B
C
F
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")
Login successful
Incorrect password
Username is required
No output
Select all statements that are correct about Python Boolean expressions.
True and False evaluates to False.
True or False evaluates to False.
not False evaluates to True.
False and False evaluates to True.
Which practices belong to the validation sequence described in the material? Select all that apply.
Check whether the input has the correct basic form.
Check whether the value is within the allowed range.
Always perform the dependent operation before validation.
Report an error or reject the input when a rule fails.
Continue only when the input is valid.
True or false: In Python, a single = is the correct operator for comparing two values in an if condition.
True
False
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.
True
False
Which Python keyword introduces the alternative branch in a two-way if-else decision?
Enter the Python keyword that means “else if” and adds another condition to a chained conditional.
Complete the statement: In Python, the punctuation mark after an if condition marks the beginning of the indented block.
Complete the statement: Inside a function, a guard clause often uses to handle an invalid or exceptional case immediately.
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.
What does classify_speed(60) return in the material's range-classification function?
Fast
Moderate
Slow
Invalid
True or false: In an if/elif chain, Python executes every branch whose condition is true.
True
False
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?
What is printed by this Python code?
items = []
if items:
print("Items found")
else:
print("No items")
Items found
No items
The list itself
An error occurs
What value is assigned to status?
age = 16
status = "adult" if age >= 18 else "minor"
minor
adult
16
An error occurs
What is the value of message after this code runs?
value = None
if value:
message = "present"
else:
message = "missing"
present
None
missing
The variable is unchanged
A program should accept either "yes" or "y" as the value of choice. Which condition correctly tests both possibilities?
if choice == "yes" or "y":
if choice == ("yes" or "y"):
if choice in "yes", "y":
if choice == "yes" or choice == "y":
A program sets records = [] and then evaluates if records:. What Python Boolean value does the condition have?
A practical review of the integrated Java skills, debugging habits, algorithm reasoning, and free-response strategies needed for AP Computer Science A.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
Learn how to create, modify, traverse, and analyze Java lists with ArrayList, wrapper types, standard algorithms, and the Collections utility class for AP Computer Science A.
Build a clear understanding of Java Boolean expressions, logical operators, selection statements, nested branching, equivalent logic, and systematic code tracing for AP Computer Science A.
A practical introduction to Java program structure, data types, operators, input and output, problem-solving strategy, testing, and debugging for AP Computer Science A.
A practical guide to Java inheritance, constructor chaining, method overriding, polymorphism, access control, and object behavior for tracing and writing AP Computer Science A programs.
A focused guide to Java classes, object references, constructors, methods, strings, wrapper classes, and API usage for AP Computer Science A.
A focused guide to Java primitive types, expression evaluation, numeric conversion, floating-point behavior, integer overflow, and common methods in the Math class for AP Computer Science A.
A focused review of Java primitive types, expression evaluation, numeric conversion, arithmetic behavior, Math methods, randomness, and tracing techniques for AP Computer Science A.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.