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
AlekseyPX
3 years ago
6

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 iterations, the program chould display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. (We are using class' with this challenge)
Input validation: Do not acept less than 1 for the number of years. Do not accept negative numbers for the monthly rainfall.
Output:
Enter the number of years: -2
Invalid. Enter 1 or greater: 2
Enter the rainfall, in inches, for each month.
Year 1 month 1: -3
Invalid. Enter 0 or greater: 3
Year 1 month 2: 5
Year 1 month 3: 7
Year 1 month 4: 9
Year 1 month 5: 6
Year1 month 6: 0
Year 1 month 7: 0
Year 1 month 8: 0
Year 1 month 9: 3
Year 1 month 10: 6
Year 1 month 11: 10
Year 1 month 12 8
Year 2 month 1: 7
Year 2 month 2: 6
Year 2 month 3: 10
Year 2 month 4: 8
Year 2 month 5: 4
Year 2 month 6: 0
Year 2 month 7: 0
Year 2 month 8: 0
Year 2 month 9: 4
Year 2 month 10: 15
Year 2 month 11: 12
Year 2 month 12: 5
Number of months: 24
Total rainfall: 128.0 inches
Average monthly rainfall: 5.333333333333333 inches (there are 15 3's)
Computers and Technology
1 answer:
babunello [35]3 years ago
7 0

Answer:

In Python:

year = int(input("Years: "))

while year<1:

   year = int(input("Invalid. Enter 1 or greater: "))

total = 0

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

   for j in range(1,13):

       month = int(input("Year "+str(i)+", Month "+str(j)+": "))

       while month<0:

           month = int(input("Invalid. Enter 0 or greater: "))

       total+=month

ave = total/(12*year)

print("Months: "+str(12 * year))

print("Total: "+str(total))

print("Average: "+str(ave))

Explanation:

This gets the number of years

year = int(input("Years: "))

This loop validates the number of years

<em>while year<1:</em>

<em>    year = int(input("Invalid. Enter 1 or greater: "))</em>

<em />

This initializes total to 0

total = 0

This iterates through the years

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

This iterates through the month of each year

   for j in range(1,13):

This gets the rainfall for each month

       month = int(input("Year "+str(i)+", Month "+str(j)+": "))

This loop validates the amount of rainfall

<em>        while month<0:</em>

<em>            month = int(input("Invalid. Enter 0 or greater: "))</em>

This calculates the total rainfall

       total+=month

This calculates the average rainfall

ave = total/(12*year)

This prints the number of month

print("Months: "+str(12 * year))

This prints the calculated total amount of rainfall

print("Total: "+str(total))

This prints the calculated average amount of rainfall

print("Average: "+str(ave))

You might be interested in
What does a column represent in a chart?
earnstyle [38]
The correct option is C.
A column chart is defined as a chart in which the data are arrranged in column. It is normally used to show data changes over a period of time or for comparison purpose. A column in a chart refers to a vertical group of cells in a work book and it shows a series of data. 
8 0
3 years ago
What is the primary difference, if any, between a web master and a web producer? While a web master maintains a company’s websit
dolphi86 [110]

Answer:

While a web master maintains a company’s websites, the web producer maintains a company’s entire web-based system.

I'm assuming that's A

6 0
3 years ago
How does the browser display the same webpage whether you enter the URL or the IP address in the address bar? what system transl
nordsb [41]
Awesome question! I love networking. When you enter a URL into your browser, your computer sends the request to your ISP or internet service provider. Your ISP has a HUGE database that coordinates the IP address to the domain name. This database is called a DNS, or Domain Name Service. So when you submit www.google.com to your ISP, they return look in the DNS and find the IP address. The ISP then returns the IP address to you. Your browser then takes the IP and connects you to the server. The server finally send the index.html file to and your browser and renders it as a web page. 

This all happens in the blink of an eye. The internet is truly amazing :D
6 0
3 years ago
Write the constructor for the Theater class. The constructor takes three int parameters, representing the number of seats per ro
sp2606 [1]

Answer:

See explaination

Explanation:

class Seat {

private boolean available;

private int tier;

public Seat(boolean isAvail, int tierNum)

{ available = isAvail;

tier = tierNum; }

public boolean isAvailable() { return available; }

public int getTier() { return tier; }

public void setAvailability(boolean isAvail) { available = isAvail; } }

//The Theater class represents a theater of seats. The number of seats per row and the number of tier 1 and tier 2 rows are

//determined by the parameters of the Theater constructor.

//Row 0 of the theaterSeats array represents the row closest to the stage.

public class Theater {

private Seat[][] theaterSeats; /** Constructs a Theater object, as described in part (a). * Precondition: seatsPerRow > 0; tier1Rows > 0; tier2Rows >= 0 */

public Theater(int seatsPerRow, int tier1Rows, int tier2Rows) {

theaterSeats= new Seat[tier1Rows+tier2Rows][seatsPerRow];

}

public boolean reassignSeat(int fromRow, int fromCol, int toRow, int toCol) {

if(theaterSeats[toRow][toCol].isAvailable()) {

int tierDestination =theaterSeats[toRow][toCol].getTier();

int tierSource =theaterSeats[fromRow][fromCol].getTier();

if(tierDestination<=tierSource) {

if(tierDestination==tierSource) {

if(fromRow<toRow) {

return false;

}else {

theaterSeats[toRow][toCol].setAvailability(false);

theaterSeats[fromRow][fromCol].setAvailability(true);

return true;

}

}

theaterSeats[toRow][toCol].setAvailability(false);

theaterSeats[fromRow][fromCol].setAvailability(true);

return true;

}else {

return false;

}

}else {

return false;

}

}

public static void main(String[] args) {

//Lets understand it with simple example

Theater t1 = new Theater(3,1,2);

//Our threater has 3 seat in each row and we have one tier 1 row and 1 tier 2 row

//total no of seat will be 9.

//Lets create our seat

t1.theaterSeats[0][0] = new Seat(true,1);

t1.theaterSeats[0][1] = new Seat(false,1);

t1.theaterSeats[0][2] = new Seat(true,1);

t1.theaterSeats[1][0] = new Seat(true,2);

t1.theaterSeats[1][1] = new Seat(true,2);

t1.theaterSeats[1][2] = new Seat(true,2);

t1.theaterSeats[2][0] = new Seat(false,2);

t1.theaterSeats[2][1] = new Seat(false,2);

t1.theaterSeats[2][2] = new Seat(true,2);

//Lets print out theater and see which seat is available or which is not

System.out.println("Theater===>");

for(int i=0;i<3;i++) {

for(int j=0;j<3;j++) {

System.out.print("["+i+"]"+"["+j+"] : "+t1.theaterSeats[i][j].isAvailable()+" ");

}

System.out.println();

}

System.out.println("(2,1) want to change seat to (0,0)");

System.out.println("["+2+"]"+"["+1+"]"+"===>"+"["+0+"]"+"["+0+"]");

t1.reassignSeat(2, 1, 0, 0);

for(int i=0;i<3;i++) {

for(int j=0;j<3;j++) {

System.out.print("["+i+"]"+"["+j+"] : "+t1.theaterSeats[i][j].isAvailable()+" ");

}

System.out.println();

}

}

}

5 0
4 years ago
In many cases, a ribbon organizes buttons and options in Select one: a. menus. b. sections. c. toolbars. d. groups.
katrin2010 [14]

Answer:

The answer is Groups

Explanation:

A ribbon organizes buttons and a program’s options into a series of groups or tabs at the top of the window. Typical ribbon tabs are composed of groups that are labeled as closely related commands. Dividing commands into groups in most Microsoft Office application helps users structure users structure the commands into related sets.

5 0
4 years ago
Read 2 more answers
Other questions:
  • How would you describe by adding comments to the coding explaining that you know what int num1 = 10; int ave = (num1+num2+num3)/
    10·1 answer
  • Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", output is: 9_
    6·1 answer
  • Rebecca completed work on a computer and is verifying the functionality of the system when she finds a new problem. This problem
    14·1 answer
  • Regular languages are closed under complement. True False
    7·1 answer
  • How am i supposed to add subtitles to a video without have to waist money???
    7·1 answer
  • Which of these is an example of input?
    6·1 answer
  • What are the characteristics of 1st generation computers​
    9·2 answers
  • What are the primary IP addresses for DNS servers hosted on the x128bit, iskytap and cloudparadox domains
    8·1 answer
  • An individual involved with the aspect of a project will be concerned with budgets and the costs associated with running a busin
    10·2 answers
  • What dose a hard drive do
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!