Question

In: Computer Science

Write a program that asks the user to enter the total precipitation for each of the...

Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches.

Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names of the months.

Here is a sample run:

Enter total precipitation for January: 3.44
Enter total precipitation for February: 3.01
Enter total precipitation for March: 4.32
Enter total precipitation for April: 4.12
Enter total precipitation for May: 4.37
Enter total precipitation for June: 4.60
Enter total precipitation for July: 5.05
Enter total precipitation for August: 3.98
Enter total precipitation for September: 4.53
Enter total precipitation for October: 3.82
Enter total precipitation for November: 3.94
Enter total precipitation for December: 4.23

Total precipitation: 49.41 inches.
Average precipitation: 4.12 inches.
July has the highest precipitation: 5.05 inches.
February has the lowest precipitation: 3.01 inches.

Notes:

  • The purpose of this problem is to practice using lists, list functions and methods, and the index system. Do not use loops or conditional branching
  • Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
  • This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.

PLEASE CODE IN PYTHON PROGRAMMING LANGUAGE

Solutions

Expert Solution

Code for the given output :-

# list for storing input values
precipitationList = []
# list of months
months = ["January","February","March","April","May","June","July",
          "August","September","October","November","December"]
# Asking value for each month without using loop and appending in precipitationList
n = float(input("Enter total precipitation for {}: ".format(months[0])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[1])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[2])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[3])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[4])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[5])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[6])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[7])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[8])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[9])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[10])))
precipitationList.append(n)
n = float(input("Enter total precipitation for {}: ".format(months[11])))
precipitationList.append(n)
# Calculating sum of precipitation using sum function
total_precipitation = sum(precipitationList)
#  Calculating Average by dividing sum with 12
average_precipitation = total_precipitation / 12
# Finding maximum precipitation using max funnction
maximum_precipitation = max(precipitationList)
# Finding minimum precipitation using min funnction
minimum_precipitation = min(precipitationList)
# getting month index by maximum and minimum precipitation using index function
max_month = precipitationList.index(maximum_precipitation)
min_month = precipitationList.index(minimum_precipitation)
print("\n")
print("Total precipitation: {} inches".format(total_precipitation))
print("Average precipitation: {:.2f} inches".format(average_precipitation))
print("{} has the highest precipitation: {} inches.".format(months[max_month],maximum_precipitation))
print("{} has the lowest precipitation: {} inches.".format(months[min_month],minimum_precipitation))

Screenshot for the above code :-

Output for the above code :-


Related Solutions

Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a C program that asks the user to enter any two integernumbers, and each...
Write a C program that asks the user to enter any two integer numbers, and each number consists of four-digits. Your program should check whether the numbers are four digits or not and in case they are not a four digit number, the program should print a message and exit, otherwise it should do the following:Print a menu as follows:Select what you want to do with the number 1-3:1- Print Greatest Common Divisor (GCD) of the two numbers.2- Print sum...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
1/Write a C program that asks the user to enter 5 nums and adds each number...
1/Write a C program that asks the user to enter 5 nums and adds each number to a total. The program should then display the total. To add to the total, the program must call the function void sum(int value, int *ptotal) passing the value the user entered and the address of the total (a local variable in main). The function should add the value to the total. Note that the function is void and does not return anything. Don't...
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,...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT