Write a function called recommend(temp, forecast) that prints out a recommendation about what to wear and bring based on the weather. temp is an integer number that represents the temperature in degrees. forecast is a string which describes the weather forecast for the day.
When the temperature is under 72 degrees, a jacket should be worn.
If the forecast is “showers”, “rain”, or “snow”, an umbrella should be brought.
Your output should be one of these sentences based on the forecast & temperature.
Based on the weather forecast, you should bring a jacket and an umbrella
Based on the weather forecast, you should bring an umbrella
Based on the weather forecast, you should bring a jacket
Weather is great! Have a nice day!
def recommend(temp, forecast):
c_t = temp < 72
c_f = forecast == 'showers' or forecast == 'rain' or forecast == 'snow'
if c_t and c_f:
rec = 'a jacket and an umbrella'
elif c_t and not c_f:
rec = 'a jacket'
elif c_f and not c_t:
rec = 'an umbrella'
return 'Based on the weather forecast, you should bring ' + rec + '\n' + 'Weather is great! Have a nice day!'
print(recommend(70, 'rain'))
print(recommend(75, 'rain'))
print(recommend(70, 'good weather'))
Comments
Leave a comment