I have an assignment as follows:
Write a program where you can enter from the keyboard up to 10 integers. If the number entered is equal to -99, stop reading numbers from the keyboard and compute the average and sum of all values (excluding -99). Print the average on the screen. Make sure you consider all the cases: less than 10 or exactly 10 numbers can be entered. After the numbers have been entered you need to make sure that the average is computed then.
I came up with the program below. Do you think my program is fine? What could be alternative solutions?
s = 0
for i in range(1, 11):
a=int(input("Enter a number: "))
if a==-99:
s = s+a
print("The sum of the numbers that you've entered excluding -99:",s-a) # minus a because we want to exclude -99
print("The average of the numbers that you've entered excluding -99:",(s-a)/(i-1)) # minus a because we want to exclude -99. i-1 in denominator because we excluded -99 from the sum.
break
else:
s = s+a
print("The sum of the number(s) that you've entered:",s)
print("The average of the number(s) that you've entered:",s/i)
continue
input("Press enter to close")
excluding -99
. Also you are displaying results after every input. \$\endgroup\$