# This program calculates the average of a series of exam scores. |print ("""Calculate the average of a bunch of exam scores. The scores can be integers or floats.""") print () list = [] # initialize variables sum 0.0 count 0.0 avg i = 0 SENTINEL VAL 9999 # input user data inputVal = float(input ("Enter a number. 9999 to quit: ")) # loop continues to iterate until the user enters 9999 while inputVal != 9999: inputVal = float(input("Enter a number. 9999 to quit: ")) if inputVal > 0 and inputVal < 100: list.append (inputVal) else: print ("Score is not in range. Please re-enter.") for i in list: sum = sum + i count = count + 1 # calculating average avg = sum / count # print result print ("These %d scores average as: %.1f" %(count, avg))

icon
Related questions
Question
100%

Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate.

You need to use a while loop to allow the user to enter numbers, one at a time, until some numeric sentinel value is entered. I recommend having a sentinel like 9999, something unlikely to be confused with an exam score. If the user enters a score < 0 or > 100 that is not the sentinel value then that score is to be rejected. Each time a legit score is entered, however, it should be added (appended) to a list.

Once the user has entered all the numbers they want, calculate and display the average of the scores rounded to 1 decimal place.

I attached my solution. I can not fix two problems: 1. It does not count right the number of iterations and avg. 2. After I type 9999(sentinel value) it gives me output: Score is not in range. Please re-enter. It supose just quit and calculate the avg. Thank you!

# This program calculates the average of a series of exam scores.
|print ("""Calculate the average of a bunch of exam scores.
The scores can be integers or floats.""")
print ()
list = []
# initialize variables
sum
0.0
count
0.0
avg
i = 0
SENTINEL VAL
9999
# input user data
inputVal = float(input ("Enter a number. 9999 to quit: "))
# loop continues to iterate until the user enters 9999
while inputVal != 9999:
inputVal = float(input("Enter a number. 9999 to quit: "))
if inputVal > 0 and inputVal < 100:
list.append (inputVal)
else:
print ("Score is not in range. Please re-enter.")
for i in list:
sum = sum + i
count = count + 1
# calculating average
avg = sum / count
# print result
print ("These %d scores average as: %.1f" %(count, avg))
Transcribed Image Text:# This program calculates the average of a series of exam scores. |print ("""Calculate the average of a bunch of exam scores. The scores can be integers or floats.""") print () list = [] # initialize variables sum 0.0 count 0.0 avg i = 0 SENTINEL VAL 9999 # input user data inputVal = float(input ("Enter a number. 9999 to quit: ")) # loop continues to iterate until the user enters 9999 while inputVal != 9999: inputVal = float(input("Enter a number. 9999 to quit: ")) if inputVal > 0 and inputVal < 100: list.append (inputVal) else: print ("Score is not in range. Please re-enter.") for i in list: sum = sum + i count = count + 1 # calculating average avg = sum / count # print result print ("These %d scores average as: %.1f" %(count, avg))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.