16.9. Rainfall Problem

Let’s imagine that you have a list that contains amounts of rainfall for each day, collected by a meteorologist. Her rain gathering equipment occasionally makes a mistake and reports a negative amount for that day. We have to ignore those. We need to write a program to (a) calculate the total rainfall by adding up all the positive integers (and only the positive integers), (b) count the number of positive integers (we will count with “1.0” so that our average can have a decimal point), and (c) print out the average rainfall at the end. Only print the average if there was some rainfall, otherwise print “No rain”.

Construct a program that correctly solves the rainfall problem

Type the program here and try it. Does it work like you thought it would?

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted of activities on this page