Skip to content

Question 16

What is the output of the following code?

1
2
3
4
5
6
7
sun, wind, rain = 0, 1, 1
if rain:
    if wind:
        print('Cold')
    print(rain)
elif sun or wind:
    print('Sweat')
Hint

Notice the initialized values of sun, wind, and rain. What would their respective Boolean equivalents be?

Solution

if rain: True (1 is a truthy value) \(\Rightarrow\) enter if block.

  • if wind: True (1 is a truthy value) \(\Rightarrow\) enter if block.
    • Print 'Cold' in the console.
  • Print the value of rain (i.e., 1), since it is still within the if rain block.

Ignore the contents of the elif block that trail afterwards.

Answer
Cold
1