I am suppose to create a function that interactively prompts for user input for temperatures for a 24 hour period (0 - 23.) Each temperature must be between -50 and 130 degrees.
If any of the values are outside of this acceptable range, the user should be asked to re-enter the value until it is within the range before going on to the next temperature.
def getTemps(hourlyTemps):
hourlyTemps.append(int(input('Enter the temperature of the hour : ')))
while True:
try:
number1 = hourlyTemps
if number1 > -50 or number1 < 130:
raise ValueError
break
except ValueError:
print("Invalid integer. The number must be in the range of -50 to 130.")
I am not sure if what I am doing can be applied to a list or if I should try a different approach. Any help would be appreciated.