In: Computer Science
Python 3.7.4 (Introductory Level)
You want to know your grade in Computer Science:
Write a program that continuously takes grades between 0 and 100 to standard input until you input "stop", at which point it should print your average to standard output.
Python 3.7.+ standard program to implement the given problem is provided below:
Note: The code indentation may lost while copying, if happens so please refer the screenshot provided to reconstruct the indentation.
Python code:
#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:
Code screenshot: