Question Detail

COS 102 If staments Objective Question

Question

What is the output of the following Python code snippet, based on the 'Multi-way Logic: Weather' example (assuming temp = 32)?
temp = 32
if temp > 30:
    print("Hot Day")
elif temp > 15:
    print("Nice Day")
else:
    print("Cold Day")
Options
A Hot Day
Correct Answer
B Nice Day
C Cold Day
D Error
Correct Answer

Option A is the correct answer.

Detailed Explanation

Page 13, 'Multi-way Logic: Weather', shows temp = 32. The first condition, if temp > 30: (i.e., 32 > 30) evaluates to True. Therefore, 'Hot Day' is printed, and the rest of the elif and else blocks are skipped.

Hint

Python evaluates conditions sequentially from top to bottom in an if-elif-else chain. The first True condition's block is executed, and then the entire structure is exited.

Question Info