Python - Conditional Statements
You want to print "Positive", "Zero", or "Negative" based on a number's value. Which code correctly uses
if, elif, and else to do this?if, elif, and else to do this?if-elif-else structureif for first condition, elif for the second, and else for all other cases.elif and else. if num > 0:
print("Positive")
if num == 0:
print("Zero")
else:
print("Negative") uses two separate if statements which can cause multiple prints. if num > 0:
print("Positive")
else if num == 0:
print("Zero")
else:
print("Negative") uses invalid syntax else if. if num > 0:
print("Positive")
elif num < 0:
print("Zero")
else:
print("Negative")'s elif num < 0 will print "Zero" for negative numbers and "Negative" for zero incorrectly.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions