Apr-05-2019, 04:39 AM
rainfall_mi is a string that contains the average number of inches of rainfall in Michigan for every month (in inches) with every month separated by a comma. Write code to compute the number of months that have more than 3 inches of rainfall. Store the result in the variable num_rainy_months. In other words, count the number of items with values > 3.0.
#given string rainfall_mi = "1.65, 1.46, 2.05, 3.03, 3.35, 3.46, 2.83, 3.23, 3.5, 2.52, 2.8, 1.85" #my attempt items = rainfall_mi.split(",") #print (items) accum = 0 for inches in items: if inches > 3.0: accum = accum + 1 num_rainy_months = accum print(num_rainy_months)
Output:12
(should be 5)