Question

In: Computer Science

In Python: Design a program that lets the user enter the total rainfall for each of...

In Python:

Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing and output described in the problem (total, average, highest and lowest).

    1. Rewrite your previous program to use a loop to ask the user for the monthly rainfall twelve times (once for each month, without needing to specify which month is which). You will need to create an empty list to hold the user’s input. Show your code.
    1. Rewrite the previous program to ask the user for the rainfall for each month, specifying the name of the month. For example, if the previous iteration asked “Enter rainfall “ then in this iteration, ask the user to “Enter rainfall for January “ then “Enter rainfall for February” etc. Show your code.

Please write this short program in Python. Thank you.

Solutions

Expert Solution

NOTE :- I HAVE ATTACHED ALL THREE PROGRAMS IN A SEQUENCE WITH THE CODE, SCREENSHOTS OF THE OUTPUT AND SCREENSHOT OF THE CODE FOR INDENTATION RESPECTIVELY.

PROGRAM 1

rain_input=[25,1,14,15,5,151,144,126,25,10,5,121] #DECLARING THE STATIC RAINFALL VALUES

#DECALRING THE MONTHS NAME
months=["January","February","March","April","May","June","July","August","September","October","November","December"]

total=sum(rain_input)   #TOTAL RAIN CALCULATION OF THE YEAR BY SUM() FUNCTION
avg=total/12    #AVERAGE OF ALL RAINFALL IN THE YEAS

#DECALRING VARIABLES FOR MAX AND MIN RAIN
max_rain=[]
min_rain=[]

#CALCULATING MAXIMUMN RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MAXIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:    #HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i>=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MAX RAINFALL
        temp=i      #SETTING THE MAXIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MAX_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:   #CHECKING IF THE MONTH VALUE IS SAME AS MAX
        max_rain.append(i)    #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MAX_RAIN LIST


#CALCULATING MINIMUM RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MINIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:#HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i<=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MINIMUM RAINFALL
        temp=i      #SETTING THE MINIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MIN_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:     #CHECKING IF THE MONTH VALUE IS SAME AS MINIMUM
        min_rain.append(i)      #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MIN_RAIN LIST


print("Total Rain => ",total)   #PRINTING THE TOTAL RAIN OF THE YEAR
print("Average Rain => ",avg)   #PRINTING THE AVERAGE RAIN OF THE YEAR

print("\nThe Maximum Rainfall Was In The Following Months=")
for i in max_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MAXIMUM RAIN AND THEIR VALUE

print("\nThe Minimum Rainfall Was In The Following Months=")
for i in min_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MINIMUM RAIN AND THEIR VALUE

OUTPUT OF THE PROGRAM

SCREENSHOT OF THE PROGRAM FOR INDENTATION

PROGRAM 2

#DECALRING A EMPTY LIST
rain_input=[]
print("Enter Rainfall=")
for i in range(12):
    rain_input.append(int(input())) #TAKING INPUT FOR 12 MONTHS WITHOUT SPECIFYING THE MONTH NAME 

months=["January","February","March","April","May","June","July","August","September","October","November","December"]  #DECALRING THE MONTHS NAME

total=sum(rain_input)   #TOTAL RAIN CALCULATION OF THE YEAR BY SUM() FUNCTION
avg=total/12    #AVERAGE OF ALL RAINFALL IN THE YEAS

#DECALRING VARIABLES FOR MAX AND MIN RAIN
max_rain=[]
min_rain=[]

#CALCULATING MAXIMUMN RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MAXIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:    #HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i>=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MAX RAINFALL
        temp=i      #SETTING THE MAXIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MAX_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:   #CHECKING IF THE MONTH VALUE IS SAME AS MAX
        max_rain.append(i)    #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MAX_RAIN LIST


#CALCULATING MINIMUM RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MINIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:#HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i<=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MINIMUM RAINFALL
        temp=i      #SETTING THE MINIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MIN_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:     #CHECKING IF THE MONTH VALUE IS SAME AS MINIMUM
        min_rain.append(i)      #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MIN_RAIN LIST


print("Total Rain => ",total)   #PRINTING THE TOTAL RAIN OF THE YEAR
print("Average Rain => ",avg)   #PRINTING THE AVERAGE RAIN OF THE YEAR

print("\nThe Maximum Rainfall Was In The Following Months=")
for i in max_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MAXIMUM RAIN AND THEIR VALUE

print("\nThe Minimum Rainfall Was In The Following Months=")
for i in min_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MINIMUM RAIN AND THEIR VALUE
    

OUTPUT OF THE PROGRAM

SCREENSHOT OF THE PROGRAM FOR INDENTATION

PROGRAM 3

#DECALRING A EMPTY LIST
rain_input=[]
#DECALRING THE MONTHS NAME
months=["January","February","March","April","May","June","July","August","September","October","November","December"]

for i in range(12):
    rain_input.append(int(input("Enter Rainfall For "+months[i]+" => "))) #GETTING THE INPUT AND PRINTING THE MONTH NAME ALONGSIDE WITH IT.

total=sum(rain_input)   #TOTAL RAIN CALCULATION OF THE YEAR BY SUM() FUNCTION
avg=total/12    #AVERAGE OF ALL RAINFALL IN THE YEAS

#DECALRING VARIABLES FOR MAX AND MIN RAIN
max_rain=[]
min_rain=[]

#CALCULATING MAXIMUMN RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MAXIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:    #HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i>=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MAX RAINFALL
        temp=i      #SETTING THE MAXIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MAX_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:   #CHECKING IF THE MONTH VALUE IS SAME AS MAX
        max_rain.append(i)    #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MAX_RAIN LIST


#CALCULATING MINIMUM RAIN
temp=rain_input[0]  #BY DEFAULT THE FIRST RAINFALL WILL BE MINIMUM

#HERE WE ARE CHECKING IF THERE ARE TWO MONTHS WITH SAME RAINFALL THEN IT SHOULD PRINT BOTH THE MONTHS RATHER THAN ONLY PRINTING ONE MONTH
for i in rain_input:#HERE INSIDE i WILL BE THE VALUE OF EACH RAINFALL OF THE YEAR
    if (i<=temp):   #IT WILL CHECK IF i IS GREATER THAN TEMP THEN CHANGE TEMP TO MINIMUM RAINFALL
        temp=i      #SETTING THE MINIMUM RAINFALL

#IF THERE ARE SAME MONTHS WITH SAME RAINFALL THEN ADDING TO THE MIN_RAIN LIST THE INDEX OF THAT MONTH
for i in range(len(rain_input)):
    if rain_input[i]==temp:     #CHECKING IF THE MONTH VALUE IS SAME AS MINIMUM
        min_rain.append(i)      #IF YE THEN ADDING THE INDEX OF THAT MONTH TO MIN_RAIN LIST


print("\nTotal Rain => ",total)   #PRINTING THE TOTAL RAIN OF THE YEAR
print("Average Rain => ",avg)   #PRINTING THE AVERAGE RAIN OF THE YEAR

print("\nThe Maximum Rainfall Was In The Following Months=")
for i in max_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MAXIMUM RAIN AND THEIR VALUE

print("\nThe Minimum Rainfall Was In The Following Months=")
for i in min_rain:
    print(months[i]," => ",rain_input[i])   #PRINTING THE MONTHS WITH MINIMUM RAIN AND THEIR VALUE

OUTPUT OF THE PROGRAM

Note: If you have any queries then let me know in the comments. If you find it helpful then a Like would be appreciated


Related Solutions

In python please design a program that lets the user enter the total rainfall for each...
In python please design a program that lets the user enter the total rainfall for each of the last 10 years into an array. The program should calculate and display the total rainfall for the decade, the average yearly rainfall, and the years with the highest and lowest amounts. Should have Indentation Comments Good Variables initializations Good questions asking for the parameters of the code Output display with explanation Screenshot
Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Requirements You must use the given function prototypes. You can add more functions if you like. def get_total_rainfall(months, months_len): def get_average_monthly_rainfall(months, months_len): def get_month_with_highest_rainfall(months, months_len): def get_month_with_lowest_rainfall(months, months_len): Design Considerations Use a global parallel array of...
Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. This is my Pthon 3.8.5 code so far: #Determine Rainfall Program for a 12 month Period #It should calculate and output the "total yearly rainfall, avg monthly rainfall, the months with highest and lowest amounts #list of...
design a program that lets the user enter the total rainfall for each of 12 months...
design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.   ---->>> Enhance the program so it sorts the array in ascending order and displays the values it contains. You can choose which sorting algorithm to use (bubble sort, selection sort, or insertion sort). Depending on your...
Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Design a program to solve Chapter 8 Programming Exercise 3 (Rainfall Statistics) in your textbook. Create parallel arrays for the month names and rainfall amounts for each month. Use month names (i.e. January, February, March, etc.)...
Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics Design a program that lets the user enter the...
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall , and the months with the highest and lowest amounts. PLEASE AND THANK YOU
How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Program on Visual Basic, VBA Create an application that lets the user enter a number of...
Program on Visual Basic, VBA Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
C++ Write a program that lets the user enter a two letters which are f and...
C++ Write a program that lets the user enter a two letters which are f and s with a length of 5. And outputs how many times it was occurred and lists the 2 most repeating pattern with 5lengths of f and s. The output display should always start at three-f(s) .Include an option where user can retry the program. Example: Input: sssfsfsfssssfffsfsssssfffsffffsfsfssffffsfsfsfssssfffffsffffffffffffssssssssfffsffffsssfsfsfsfssssfffsssfsfsffffffssssssffffsssfsfsfsss Output: The most repeating 5lengths of pattern is: fffsf and occurred 6times. Output2: The second most repeating...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT