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

Respuesta :

Answer: -1 usually represents infinity.

Explanation:

It would keep going forever and not be able to stop without manually stopping it.

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.

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE