IDNLearn.com provides a seamless experience for finding the answers you need. Join our community to receive prompt and reliable responses to your questions from experienced professionals.
Sagot :
Answer:
In Python:
year = int(input("Years: "))
while year<1:
year = int(input("Invalid. Enter 1 or greater: "))
total = 0
for i in range(1,year+1):
for j in range(1,13):
month = int(input("Year "+str(i)+", Month "+str(j)+": "))
while month<0:
month = int(input("Invalid. Enter 0 or greater: "))
total+=month
ave = total/(12*year)
print("Months: "+str(12 * year))
print("Total: "+str(total))
print("Average: "+str(ave))
Explanation:
This gets the number of years
year = int(input("Years: "))
This loop validates the number of years
while year<1:
year = int(input("Invalid. Enter 1 or greater: "))
This initializes total to 0
total = 0
This iterates through the years
for i in range(1,year+1):
This iterates through the month of each year
for j in range(1,13):
This gets the rainfall for each month
month = int(input("Year "+str(i)+", Month "+str(j)+": "))
This loop validates the amount of rainfall
while month<0:
month = int(input("Invalid. Enter 0 or greater: "))
This calculates the total rainfall
total+=month
This calculates the average rainfall
ave = total/(12*year)
This prints the number of month
print("Months: "+str(12 * year))
This prints the calculated total amount of rainfall
print("Total: "+str(total))
This prints the calculated average amount of rainfall
print("Average: "+str(ave))
We appreciate every question and answer you provide. Keep engaging and finding the best solutions. This community is the perfect place to learn and grow together. Your search for solutions ends at IDNLearn.com. Thank you for visiting, and we look forward to helping you again.