Question Detail

COS 102 If staments Objective Question

Question

Considering the 'Multi-way Logic: Weather' example on page 13:
temp = 32
if temp > 30:
print('Hot Day')
elif temp > 15:
print('Nice Day')
else:
print('Cold Day')
What will be the output?
Options
A Hot Day
Correct Answer
B Nice Day
C Cold Day
D An error
Correct Answer

Option A is the correct answer.

Detailed Explanation

As per page 13, temp is 32. The first condition temp > 30 (32 > 30) is True. So, print('Hot Day') will execute, and the rest of the elif and else blocks will be skipped.

Hint

Remember that in an `if-elif-else` chain, only the first `True` condition's block is executed.

Question Info