Find Average of User Input Defined number of Scores - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Find Average of User Input Defined number of Scores (/thread-22020.html) |
Find Average of User Input Defined number of Scores - DustinKlent - Oct-24-2019 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? RE: Find Average of User Input Defined number of Scores - Larz60+ - Oct-25-2019 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)}") |