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?
Options
A Hot Day
B Nice Day
Correct Answer
C Cold Day
D Error
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 13, 'Multi-way Logic: Weather': temp = 32. The first condition if temp > 30 (32 > 30) is True, so 'Hot Day' would be printed. Wait, I made a mistake here. The image shows temp = 32 and if temp > 30: print('Hot Day'). Ah, the code on the slide says temp = 32. So if temp is 32, then temp > 30 is True, and it should print 'Hot Day'. Let me correct my thinking process.

Hint

Carefully trace the value of 'temp' through each condition in the if-elif-else structure.

Question Info