111k views
11 votes
Write a program that will input a list of test scores in from the keyboard. When the user enters -1, print the average.

What do you need to be careful about when using -1 to stop a loop?



Enter the Scores:
45
100
-1

The average is: 72.5

1 Answer

4 votes

print("Enter the Scores:")

total = []

while True:

num = int(input())

if num == -1:

break

total.append(num)

print("The average is:",(sum(total)/len(total)))

I wrote my code in python 3.8. Also, you have to be careful about adding -1 to the total. You don't want to count -1 in the average.

User Farajnew
by
5.4k points