Answer to Question #293743 in Python for hsoxx01

Question #293743

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!




1
Expert's answer
2022-02-04T07:59:30-0500
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'))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS