Question

PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED


Average Rainfall Filenames: rainfallalg.pdf, rainfall.py write a program that uses nested 1oops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of ar. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month After all iterations, the program should display the number of months, the tota inches of rainfall, and the average raintall per month for the entire period nput validation: Do not accept a number less than 1 for the number of years Do not accept negative numbers for the monthly rainfali. Example Output: e Python Shell Enter the number of year 2 :nv*11d. Monthly rainfall oan not be negstire. Enter he monthiy in fal: fer month 21 2 Enter the monthly zsin fel fes monEn 3 2 Eater Dse monthly zasn fai1 fez month 41 2 嚣nc@ごじ jtonshly rain f.21 t。r month 6: 2 Enter the monthly :san fall for month 2 Entler the monthly rain fell for nonth 9: 2 Enter the monthly r3zn fall for month ::: 2 Enter the monthly zain tal2 toz month 22: 2.9 Enter the montnay eain tall tor month i2: 2.5 rnt.r the monthly tsin fall ter month 2 Enter the monthly rain tall for nantn s; 3 Enter the monthly rain fail torxanch Enter the monthly rais fall for monch s: 3 Entez the monchiy sain tall tor month 6: 9 Encez che monchly zoin raik tor nonth B: 3 Enter the monthly rain fall tor month 9 2 Ence: the monthly art t 11 to r month 10: 2 Encer the monchly zean fai1 or month 12 2 Enter the monchly rain fall tor month 12: 2 57.5 2.39583333333333ss Total Rainfaldz Ln: 45 Col: 4

home / study / engineering / computer science / questions and answers / python programming - code the program based on ...

Your question has been answered! Rate it below.

Let us know if you got a helpful answer.

Question: PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE...

Bookmark

PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED

Rainfall Algorithm

Declare and initialize variables and constants

int numYears, numMonths

float monthlyRain, totalRain, averageRain

Intro

while numYears < 1:

prompt for numYears

if numYears < 1:

    Display Invalid

for year in range(1,numYears + 1):

    for month range(1,13):

         while monthlyRain <= 0:

             Prompt for monthlyRain

             if monthlyRain <= 0:

                 Display Invalid

         Add to accumulator

         totalRain += monthlyRain

Calculate numMonths

numMonths = numYears * 12

Calculate averageRain

averageRain = totalRain / numMonths

Display numMonths, totalRain, averageRain

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Variables need to be created to reference total rainfall, monthly rainfall,
# average rainfall, the number of years, and the total number of months
total_rainfall = 0.0
monthly_rainfall = 0.0
average_rainfall = 0.0
years = 0
total_months = 0

# Ask the user for the number of years
years = int(input('Enter the number of years: '))

# Write a for loop and incorporate an accumulator variable to keep a running total
for years in range(years):
    print('For year:', years + 1)
    for month in range(12):
        monthly_rainfall = float(input('Enter the inches of rainfall for the month: '))
        total_months += 1
        # Add to the total rainfall month
        total_rainfall += monthly_rainfall

# Calculate average rain fall for the total period
average_rainfall = total_rainfall / total_months

print('For', total_months, 'months')
print('Total rainfall: ', format(total_rainfall, '.2f'), 'inches')
print('Average monthly rainfall: ', format(average_rainfall, '.2f'), 'inches')
Add a comment
Know the answer?
Add Answer to:
PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall 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 twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations,...

  • qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a...

    qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a string array to hold the months of the year. Call it anything you want to just make sure it's a string array is at the end of the name, e.g. months). Create a DATA statement that holds the month names: DATA "jan","Feb", "Mar" etc. Next you'll need a FOR loop to READ the DATA into the array, Call a SUB to get the rainfall...

  • the code is in visual basic 376 Chapter 6 Loop Structures Case Programming Assignments con Most...

    the code is in visual basic 376 Chapter 6 Loop Structures Case Programming Assignments con Most Rainfall in the USA USE CASE DEFINITION e Windows application opens with the heading "Most Rainfall in US - Kauai," a ListBox object that displays the monthly rainfall amounts, an i amounts in inches mage, and a Button object that allows the user to begin entering their rainfall 2. A menu bar displays the File menu, which has two menu items: Clear and Exit....

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Data Programming l: PYTHON 1. Write a program that computes your gross pay. Your code should...

    Data Programming l: PYTHON 1. Write a program that computes your gross pay. Your code should get two numbers: hours and rate per hour. You should give the employee 1.75 times the hourly rate for hours worked above 40 hours. Output: Your gross pay is $487.5 2. Rewrite the previous program using try and except so that your program handles non-numeric inputs gracefully by printing a message and exiting the program. The following shows two executions of the program with...

  • Hello I am taking an Introduction to Programming class and I need help coming up with...

    Hello I am taking an Introduction to Programming class and I need help coming up with a Psuedocode for an algorithm. Here is the assignment: 1. Use an array to prompt the user to enter a credit card account number 2. Use the sequential search algorithm to locate the credit card number entered by the user 3. If the credit card number is NOT in the array, display a message indicating the number is invalid 4. If the credit card...

  • Write a python program where you create a list (you an create it in code you...

    Write a python program where you create a list (you an create it in code you do not have to use input() statements) that represents the total rainfall for each of 12 months (assume that element 0 is January and element 11 is December). The program should calculate and display the: 1) total rainfall for the year; 2) the average monthly rainfall; 3) the months with the highest and lowest amounts. You need to figure out how to access each...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT