Python refuses to run the program below. Which statement correctly describes the problem?
n = 0
if n > 0:
print("positive")
else if n < 0:
print("negative")
else:
print("zero")
Write elif n < 0:.
Conditional Statements · Exercise 3 of 4
Each Python program has a mistake in its conditions: a syntax error, an exception at run time, or a logical bug such as a wrong branch order. Choose the option that names the real problem.
Python refuses to run the program below. Which statement correctly describes the problem?
n = 0
if n > 0:
print("positive")
else if n < 0:
print("negative")
else:
print("zero")
Write elif n < 0:.
Python refuses to run the program below. Which statement correctly describes the problem?
score = 72
if score >= 90:
print("A")
else:
print("Below A")
elif score >= 70:
print("B")
The order is always if, then any number of elif, then at most one else.
Python refuses to run the program below. Which statement correctly describes the problem?
stock = 0
if stock > 0:
# TODO: allow ordering
else:
print("Out of stock")
Comments are discarded, leaving the if with no body (IndentationError: expected an indented block). pass fixes it.
Python refuses to run the program below. Which statement correctly describes the problem?
balance = 500
if balance >= 1000:
print("Premium")
else:
print("Regular")
The error is "unindent does not match any outer indentation level". Align else with if.
Python refuses to run the program below. Which statement correctly describes the problem?
QUIT = "q"
command = "x"
match command:
case QUIT:
print("Quitting")
case _:
print("Other command")
Python reports "name capture 'QUIT' makes remaining patterns unreachable". Use case "q": or a class constant such as case Command.QUIT:.
The program below stops with an error. Which statement correctly describes the problem?
marks = 30
if marks >= 40:
result = "pass"
print("Result:", result)
Give it a value on every path: add else: result = "fail", or set result = "fail" before the if.
A student with 95 marks should get "Distinction". Which statement correctly identifies the bug?
marks = 95
if marks >= 40:
print("Pass")
elif marks >= 75:
print("First class")
elif marks >= 90:
print("Distinction")
Only the first true branch runs. Test >= 90, then >= 75, then >= 40.
Exactly one label should be printed for a temperature. Which statement correctly identifies the bug?
temp = 45
if temp > 40:
print("Hot")
if temp > 25:
print("Warm")
else:
print("Cold")
With elif temp > 25:, only "Hot" is printed for 45.
The user types 1 but the program prints "Invalid choice". Which statement correctly identifies the bug?
choice = input()
if choice == 1:
print("Starting game")
else:
print("Invalid choice")
No error is raised – str and int are simply never equal. Use if choice == "1": or int(choice).
Anyone aged 18 or more may vote, but an 18-year-old is told "Not eligible". Which statement correctly identifies the bug?
age = 18
if age > 18:
print("Eligible to vote")
else:
print("Not eligible")
Boundary values are where conditions usually go wrong – always test them.
Timed online tests with instant scores and explanations.