Python Forum
Need help on sequence and loop homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help on sequence and loop homework
#1
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)))
Reply
#2
I recommend to move input validation into separate function as well as add check for values <=0 as required in assignment description.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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?
Reply
#4
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a list from a sequence without while-loop schniefen 2 2,374 Apr-01-2019, 07:40 PM
Last Post: nilamo
  Loop Homework Help Travisbulls34 5 4,510 Oct-16-2018, 12:32 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020