Python Forum
Need help on sequence and loop homework - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Need help on sequence and loop homework (/thread-30758.html)



Need help on sequence and loop homework - vzsnv - Nov-04-2020

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ā€

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)))



RE: Need help on sequence and loop homework - perfringo - Nov-04-2020

I recommend to move input validation into separate function as well as add check for values <=0 as required in assignment description.


RE: Need help on sequence and loop homework - vzsnv - Nov-04-2020

(Nov-04-2020, 01:55 PM)perfringo Wrote: I recommend to move input validation into separate function as well as add check for values <=0 as required in assignment description.

can show me exactly where?


RE: Need help on sequence and loop homework - perfringo - Nov-04-2020

vzsnv Wrote:can show me exactly where?

Quote: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.