Course Content
Introduction to Python
Introduction to Python
Challenge: Weather Adviser
Recall the exercise from two chapters back. In that challenge, you crafted an if
/else
statement to determine if a number was even or odd. Now, let's create another conditional structure that identifies zeros, positive numbers, and negative numbers.
Swipe to start coding
You have been given a variable temperature
, representing the current outdoor temperature in degrees Celsius.
Your goals:
Classify the temperature into one of the following categories:
- If
temperature
is above30
, store"Hot"
in the variableweather_status
. - If
temperature
is between15
and30
(inclusive), store"Warm"
inweather_status
. - If
temperature
is between0
and14
(inclusive), store"Cool"
inweather_status
. - Otherwise, store
"Cold"
inweather_status
.
Check if it’s safe to go outside using the following rules:
- If
weather_status
is"Hot"
, store"Stay hydrated"
inoutdoor_advice
. - If
weather_status
is"Warm"
or"Cool"
, store"Great weather for a walk"
inoutdoor_advice
. - Otherwise, store
"Wear a coat"
inoutdoor_advice
.
Solution
Thanks for your feedback!
Challenge: Weather Adviser
Recall the exercise from two chapters back. In that challenge, you crafted an if
/else
statement to determine if a number was even or odd. Now, let's create another conditional structure that identifies zeros, positive numbers, and negative numbers.
Swipe to start coding
You have been given a variable temperature
, representing the current outdoor temperature in degrees Celsius.
Your goals:
Classify the temperature into one of the following categories:
- If
temperature
is above30
, store"Hot"
in the variableweather_status
. - If
temperature
is between15
and30
(inclusive), store"Warm"
inweather_status
. - If
temperature
is between0
and14
(inclusive), store"Cool"
inweather_status
. - Otherwise, store
"Cold"
inweather_status
.
Check if it’s safe to go outside using the following rules:
- If
weather_status
is"Hot"
, store"Stay hydrated"
inoutdoor_advice
. - If
weather_status
is"Warm"
or"Cool"
, store"Great weather for a walk"
inoutdoor_advice
. - Otherwise, store
"Wear a coat"
inoutdoor_advice
.
Solution
Thanks for your feedback!