# 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))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education