Paste Search Dynamic
Problem: Given information abo
  1. total_inches = 0
  2. while true:
  3.     try:
  4.         num_years = int(input("Enter number of years: "))
  5.         break
  6.     except valueerror:
  7.         continue
  8. if num_years < 1:
  9.    print("err: num_years < 1")
  10.    quit()
  11.  
  12. for i in range(1, num_years+1, 1):
  13.     print("Year %d" % i)
  14.     c = 1
  15.     while c < 13:
  16.         try:
  17.             inches = float(input("Month %d. Enter inches (\") of rainfall: " % c))
  18.         except valueerror:
  19.             continue
  20.         if inches < 0:
  21.            print("err: inches < 0")
  22.            continue
  23.         else:
  24.            total_inches += inches
  25.         c += 1
  26. print("Total number of months %d" % (num_years*12))
  27. print("Total rainfall %0.4f\"" % total_inches)
  28. print("Average rainfall %0.4f\"" % (total_inches / (num_years*12)))
  29.  
Parsed in 0.008 seconds