Nov-04-2020, 12:35 PM
A weatherman is keeping track of the snowfall for months 1 through 3 (January – March). For each month, the total amount of snowfall has to should be prompted for and accumulated. The total snowfall will be displayed at the end of the 3-month period. The program should also display the average amount of snowfall for the 3 months and the highest amount of snowfall during the 3-month period.
The weatherman also wants to find out if there has been a record set there must be a test to see if the total snowfall amount was greater than 24 inches. If there was more than 24 inches then a message should display the number of inches that broke the record OR if the record was not broken then display a message that says the snowfall was average for the season.
The program should also check to make sure that the snowfall amount entered for each month is not less than zero. If a zero is entered then the program should prompt the user to try again to enter the correct data.
I am still having trouble with the snowfall measurement I’m not sure how print out of the Snowfall did not accumulate more than 24”
The weatherman also wants to find out if there has been a record set there must be a test to see if the total snowfall amount was greater than 24 inches. If there was more than 24 inches then a message should display the number of inches that broke the record OR if the record was not broken then display a message that says the snowfall was average for the season.
The program should also check to make sure that the snowfall amount entered for each month is not less than zero. If a zero is entered then the program should prompt the user to try again to enter the correct data.
I am still having trouble with the snowfall measurement I’m not sure how print out of the Snowfall did not accumulate more than 24”
months=['january','february','march',] monthly_snowfall=[] for month in months: parsed=False while not parsed: #This will keep prompting the user for input until parsed is True which will only happen if there was no exception. try: snowfall=float(input("Enter snowfall in inches for the month {}: ".format(month))) parsed=True except ValueError: print('Your input is invalid') monthly_snowfall.append(snowfall) print("Total amount of snowfall:{}".format( sum(monthly_snowfall))) print("Average monthly snowfall:{}".format( sum(monthly_snowfall)/len(monthly_snowfall))) print("Highest amount of snowfall:{}".format( max(monthly_snowfall))) print("Lowest amount of snowfall:{}".format( max(monthly_snowfall)))