0
votes

I am writing a program for a course that takes user input exam scores and averages them. I have a functioning program, however I need to add a function that uses a range to identify scores entered outside of the 1-100 range and display a message "score out of range. please re enter".

Here is what I have so far:

SENTINEL = float(9999)

scores = []
while True:
    number = float(input("Enter exam score (9999 to quit): "))
    if number == SENTINEL:
        break
    scores.append(number)

if not scores:
    print("No scores entered")
else:
    avg = sum(scores)/len(scores)
    print("average of ", len(scores), " test scores is :", avg)   
1
You've already implemented a check to see if the user entered a special input, 9999, what's stopping you from implementing a check to see if they input a number that's more than 100 or less than 1? - user5407570

1 Answers

1
votes

Try this:

SENTINEL = float(9999)

scores = []
while True:
    number = float(input("Enter exam score (9999 to quit): "))

    while number != SENTINEL and (number < 1 or number > 100):
        number = float(input("score out of range. please re enter: "))

    if number == SENTINEL:
        break

    scores.append(number)

if not scores:
    print("No scores entered")
else:
    avg = sum(scores)/len(scores)
    print("average of ", len(scores), " test scores is :", avg)