1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
defon
3 years ago
3

Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program sh

ould 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 the iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.

Computers and Technology
1 answer:
Andreas93 [3]3 years ago
7 0

Answer:

Here is the Python program:

#prompts user to enter no of years

years = int(input('Enter the number of years: '))  

months = 12  # stores no of months in a year i.e. 12

sum = 0   # stores the total inches of rainfall

if years < 1: #if input year value is less than 1

    print("Invalid year")        #displays invalid year message

else:  #if input year value is greater than greater than 0

   for year in range(years):  #iterates once for every year

       print('For year: ', year + 1,' ')  #prints For year for each input year

       for month in range(months):   # iterates for each month 12 times

           print('Enter the inches of rainfall for month ', month + 1,' ')

#asks user for inches of rainfall for each of 12 months

           rainfall = int(input())  # takes value of rainfall inches for each month

           sum = sum + rainfall  # stores total rainfall inches

           

   total_months = years * months  #stores number of months

   average_rainfall = sum / total_months  #store average rainfall per month

       

print('Total inches of rainfall: ', sum) # prints total rainfall inches

print('Number of months: ', total_months)  #print total months

print('Average rainfall per month: ', format(average_rainfall, '.3f'), 'inches')

#prints the value of average rainfall per month up to 3 decimal places

Explanation:

This program uses nested loops to take data from user and calculate average rainfall over a period of years. The program prompts user to enter the number of years and the outer loop iterates for each year entered by the user. For example if user entered 3 then the outer loop iterates 3 times for each year 1, year 2 and year 3. The inner loop asks user for inches of rainfall for each of the 12 months so it iterates 12 times. For example for 3 years and 12 months in each year the inner loop asks the user 36 times to enter rainfall inches. Every time the rainfall inches are given by user that value is added to the total value (sum) at every iteration. Then the total_months value is calculated by multiplying input year with months. If input year is 3 then total_months= 3 * 12 = 36. The average rainfall is calculated by dividing value of sum to value of total_months. Finally these values are displayed on output screen using print(). The program along with output is attached.

You might be interested in
The use of electronic media, information, and communication technologies to deliver instruction where students are not required
topjm [15]

Answer:

Online Learning

Explanation:

7 0
4 years ago
(10 LC)
barxatty [35]

Answer:

college A

Explanation:

7 0
3 years ago
Which scenario describes a student citing an online source in his or her work?
dimaraw [331]

Answer:

D Ling includes the name of a source’s author in her report.

Explanation: just use it lol

4 0
3 years ago
Read 2 more answers
What are some of the challenges that could arise from setting up a file management system on a computer
Katarina [22]
<span>You could download some software that could mess up your whole computer.</span>
3 0
3 years ago
Summary about Interface Design in system analysis
Anit [1.1K]

Answer:

Explanation:Systems Analysis

It is a process of collecting and interpreting facts, identifying the problems, and decomposition of a system into its components.

System analysis is conducted for the purpose of studying a system or its parts in order to identify its objectives. It is a problem solving technique that improves the system and ensures that all the components of the system work efficiently to accomplish their purpose.

Systems Design

It is a process of planning a new business system or replacing an existing system by defining its components or modules to satisfy the specific requirements. Before planning, you need to understand the old system thoroughly and determine how computers can best be used in order to operate efficiently.

System Design focuses on how to accomplish the objective of the system.

System Analysis and Design (SAD) mainly focuses on −

Systems

Processes

Technology

5 0
2 years ago
Other questions:
  • The sheets that supply the data in a summary sheet are called the
    10·1 answer
  • Retype the statements, correcting the syntax errors.
    9·1 answer
  • Which css property is used to change the text color of an element?
    15·1 answer
  • How to hard reset a iphone 7 without computer
    8·2 answers
  • A technician is using a network-attached desktop computer with a Type 2 hypervisor to run two VMs. One of the VMs is infected wi
    14·1 answer
  • The two main methods of verification
    6·1 answer
  • On the topic of "Bridging the Digital Divide", why should companies consider the digital divide?
    9·1 answer
  • HELP!!!!!!!
    8·1 answer
  • The CUBE extension enables you to get a subtotal for each column listed in the expression, in addition to a grand total for the
    11·1 answer
  • Your connection to this site is not secure how to fix.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!