Question

In: Computer Science

Ask the user how many days that they collected gems. A loop you write should loop...

Ask the user how many days that they collected gems. A loop you write should loop how many days the user enters. If the user enters 5 days, then the loop should loop 5 times to collect the data from each day.

So, each loop iteration represents a day. In each loop iteration, ask the user how many gems they collected that day. After the loop finishes gathering the data for each day, calculate the total and average gems collected. Display the average as a float value.

TIP: To find the average, divide the sum of the numbers by the number of numbers. In the output below, the average is 15/5 = 3.0. Display the average as a float value.

Sample input/output (your output should match exactly):

How many days did you collect gems? 5

Enter the number of gems collected on day 1: 5

Enter the number of gems collected on day 2: 4

Enter the number of gems collected on day 3: 3

Enter the number of gems collected on day 4: 2

Enter the number of gems collected on day 5: 1

Total gems collected: 15

Average gems collected per day: 3.0

Another sample input/output (your output should match exactly):

How many days did you collect gems? 6

Enter the number of gems collected on day 1: 2

Enter the number of gems collected on day 2: 2

Enter the number of gems collected on day 3: 2

Enter the number of gems collected on day 4: 6

Enter the number of gems collected on day 5: 3

Enter the number of gems collected on day 6: 4

Total gems collected: 19

Average gems collected per day: 3.16

Solutions

Expert Solution

Source Code:

Output:

Code to Copy (refer above images of code for indentation):

#variables
total=0
average=0
#read how many days from user
gems=int(input("How many days did you collect gems? "))
for i in range(gems):
#read data from user
print("Enter the number of gems collected on day ",i+1,end=": ")
n=int(input())
#calculate total
total+=n
#calculate average
average=total/gems
#print total and average
print("Total gems collected: ",total)
print("Average gems collected per day: ",average)


Related Solutions

Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
in java Write a while loop to ask the user to type number of hours(double) they...
in java Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than 0 and less than 5, then:  salary = numberofhours * 12, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 12, then: salary = numberofours * 14, loop continues, the user can type another number If...
Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Write a program that displays a weekly payroll report. A loop in the program should ask...
Write a program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: Do not accept negative numbers for any of the items entered. Do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT