0
Help me please
Write a program to calculate the average daily snowfall for each of three winter months (January, February, March) and the average daily snowfall for the three-month winter period. Only can do this using One input statement
4 Answers
0
1. Ask the user for the year
2. Ask the user for the amount of snowfall (in inches) during each of the winter months (January, February, March). Be sure to include the name of the month in your request to the user. This should be implemented using ONE input statement, not three. [This doesn't mean that you should ask for all three months in one statement.]
Assumption:
1. If the year is evenly divisible by 4 it is a leap year, i.e., February has 29 days [not quite true, but close enough for this exercise].
Output:
1. Print the average daily snowfall for each of the 3 months (use name of month in the output) ⊠two decimal places. This should be implemented using ONE print statement, not three. [This doesn't mean that you should print all three monthly results in one statement.]
2. Print the average daily snowfall for the three month period (use the year in the output) ⊠two decimal places.
0
I keep getting an error message as im trying all of this and it is frustratating thank you for ur response đŻ
0
This should do what asked:
try:
months = ['January','February','March']
stat = {}
year = int(input("Year: "))
# purist section > (you may skip it)
assert(year!=0), "there is no such thing as year '0' in Gregorian calendar!"
if year<0: # lets get some precise statistics for BC years!
year = -year + 3
# < purist section end
extra_day = (year%4 == 0)
valid_size = {'January':31,'February':28 + extra_day, 'March':31}
total_sum = 0
total_days = 0
for month in months:
stat[month] = [float(y) for y in input("{0}: ".format(month)).split()]
assert(len(stat[month]) == valid_size[month]), "wrong number of inputs for {0} (total: {1}, expected: {2})".format(month, len(stat[month]), valid_size[month])
for month in months:
month_sum = sum(stat[month])
month_days = len(stat[month])
print(month + " average: " + "{:.2f}".format(month_sum/month_days))
total_sum += month_sum
total_days += month_days
print("total average: " + "{:.2f}".format(total_sum/total_days))
except AssertionError as e:
print("Error: {0}".format(e.args[0]))
0
Thank you i appreciate will try it and let you know how it goes ! Bless !