BlockPy: 9A2.3) Rainfall Accumulates Write a program (not a function) that repeatedly takes in user input representing daily rainfall measurements (non-negative integers) until it encounters the integer 99999. The program should output the average of the numbers encountered before 99999. Ignore negative numbers and any user input that is not made up entirely of digits. If no valid numbers are entered, then print out 0 instead.
Added by Robin F.
Close
Step 1
First, we need to initialize some variables. We need a variable to keep track of the total rainfall and a variable to keep track of the number of valid inputs. Let's call these `total_rainfall` and `num_valid_inputs`, respectively. We'll start both of these at Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 98 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.
James K.
Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate four times, once for each quarter. Each iteration of the inner loop will ask the user for the inches of rainfall for that quarter.
Cora M.
(Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have becn read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. Here is a sample run: Enter an integer, the input ends if it is 0:1 Enter an integer, the input ends if it is 0:2 Enter an integer, the input ends if it is 0:-1 Enter an integer, the input ends if it is 0: 3 Enter an integer, the input ends if it is 0: The number of positives is 3 The number of negatives is 1 The total is 5 The average is 1.25 Enter an integer, the input ends if it is 0: 0 You didn't enter any number
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD