Python - Conditional Statements
You want to print 'Good morning' if the hour is less than 12, 'Good afternoon' if hour is between 12 and 18 (inclusive), and 'Good evening' otherwise. Which code correctly uses conditional statements?
if, elif, and elseelif correctly and covers all hour ranges without overlap.if statements causing multiple prints; if hour < 12:
print('Good morning')
else if 12 <= hour <= 18:
print('Good afternoon')
else:
print('Good evening') uses invalid 'else if' syntax; if hour < 12:
print('Good morning')
elif hour > 12 and hour < 18:
print('Good afternoon')
else:
print('Good evening') misses equality for 12 and 18 in afternoon range.if, elif, and else and correct ranges -> Option Delif for multiple conditions [OK]elif for multiple exclusive conditions [OK]if causing multiple outputs15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions