# the variable to store count
scoresCount = 0
# the variable to store scores sum
scoreSum = 0
# the variable to store the input
inp = ''
# user prompt
print("Please inp the grades one by one, inp 'stop' to quit")
# repeat while input is not stop
while inp != "stop":
inp = input('Enter the grade:')
# if input is not stop and is a number
if inp != "stop" and inp.isdigit():
# add the input grade to the sum
scoreSum += int(inp)
# increment the scores count
scoresCount = scoresCount + 1
# print the average to standard output
print("The average of entered grades is: ")
print(float(scoreSum) / scoresCount)
Output:
Comments
Leave a comment