Question #83381

3. Squirrels: The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature from the user print out to the user if the squirrels can play or not. (You may want to ask if it is summer)

Expert's answer

SummerTime = None; temperature = None # variables


while SummerTime != "y" and SummerTime != "n" : # initializing SummerTime

SummerTime = input("Is it Summer(y/n): ")


while type(temperature) != int : # initializing temperature

try : temperature = int(input("Temperature in degrees: "))

except : continue


if SummerTime == "y" : # responding

if 60 <= temperature <= 100 : print("Squirrels are safe to play!")

else : print("Squirrels should not play!")

elif 60 <= temperature <= 90 : print("Squirrels are safe to play!")

else : print("Squirrels should not play!")


Python Console:


Is it Summer(y/n): n

Temperature in degrees: 67

Squirrels are safe to play!


Process finished with exit code 0

LATEST TUTORIALS
APPROVED BY CLIENTS