Question

In: Computer Science

Write a Python program that allows the user to enter the total rainfall for each of...

Write a Python program that allows the user to 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, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September 3.7 inches October 5.1 inches November 7.2 inches December 8.3 inches

Write comments through both programs (file creation program, and display program) telling what the program is doing

Solutions

Expert Solution

Hi,

Please find code below, all the line start with '#' are comments.

=============Code=================================

#Taking Year as a list. In which later, we will be appending the user input(rainfall in each month)
year=[]

#Declaring a list of months to track the rainfall in each month
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October","November","December" ]

# Asking user to input the rainfall in each month. This will be the decimal value, hence we are taking it as float
# Each line from line number 9 to 20, suggest user to enter rainfall in inches and we are saving it in variables
jan=float(input('Please enter January rainfall in inches: '))
feb=float(input('Please enter February rainfall in inches: '))
mar=float(input('Please enter March rainfall in inches: '))
apr=float(input('Please enter April rainfall in inches: '))
may=float(input('Please enter May rainfall in inches: '))
jun=float(input('Please enter June rainfall in inches: '))
jul=float(input('Please enter July rainfall in inches: '))
aug=float(input('Please enter August rainfall in inches: '))
sep=float(input('Please enter September rainfall in inches: '))
oct=float(input('Please enter October rainfall in inches: '))
nov=float(input('Please enter November rainfall in inches: '))
dec=float(input('Please enter December rainfall in inches: '))

# Once we are done with the user input (rainfall in each month), we will append the above variables into the 'year' list, which
# is declared in 1st line.
# We have used 'extend' because we are combining the list with all the value entered by user
# The below line suggest, We are extending our 'Year' list with the value user has entered
year.extend((jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec))

# Now we are defining a total function which will calculate the total rainfall in a year
# Using sum function to get the total of sum of the list year
def total():
    print('The total rainfall is ', sum(year),' inches')
total()

# Now we are defining a average function which will calculate the average rainfall in a year
def average():
    print('The average rainfall is', float(sum(year))/len(year), 'inches')
average()

# Now we are defining a highest function which will calculate the highest rainfall in a month
# In the below function we have 1st retrieved the max value(highest rainfall) in the list(year)
# Then we are used the max value( high variable) to find the index, and that index we are fetching in months list(declared in line 5)
def highest():
    high = max(year)
    month = months[year.index(high)]
    print('The highest rainfall is {max} inches in a month of {month}'.format(max=max(year),month=month))
highest()

# Now we are defining a lowest function which will calculate the lowest rainfall in a month
# This function works exactly like thw above function, except we are using min function to fetch minimum value in list
def lowest():
    low = min(year)
    month = months[year.index(low)]
    print('The lowest rainfall is {min} inches in the month of {month}'.format(min=min(year),month=month))
lowest()


================End======================================


=======================Screen prints( refer it for indentation)==================================

==============Please consider upvoting me, if this code helps you========Thanks=========


Related Solutions

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...
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
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
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 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.)...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT