Python Forum

Full Version: Find Average of User Input Defined number of Scores
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am attempting to write a short practice script that finds the average of a user defined number of scores.

Here is the code I have:

total = int(input('How many scores are there? '))
total_sum = 0

for i in range(total):

    Scores = float(input('Enter a score : '))

total_sum += Scores

avg = Scores / total_sum

print ('The average of the scores is: ', avg)
My goal is for this to calculate the average but it doesn't seem to be doing that. What it's doing is calculating something else. No matter how I change it up it keeps giving me odd answers.

Can anyone tell me what I'm doing wrong?
scores = []
while True:
    try:
        score = int(input('Enter a score or -1 to quit: '))
    except ValueError:
        print(f"Please enter a number")
        continue
    if score == -1:
        break
    scores.append(score)
print(f"Mean of scores is {sum(scores)/len(scores)}")