I am trying to average grades using a while loop. Here is the program requirements:
Let the user enter grades to average. The user may type any number of grades; when he or she types “quit” or “Quit” print the average, rounded to two decimal places.
Please keep advice relatively simple. First time programming. Only am familiar with for loops and while loops and if else statements right now.
I was given this skeleton code:
def main():
'''Average grades entered by the user'''
#Set the total to 0
#Set the grade count to 0
#Get a grade
#While the grade is not "quit" or "Quit"
# Add the grade to total
# Add one to the grade count
# Get a grade
#Average the grades
#Round the average to two decimal places
#Print the average
main() #Start execution
Here is my code thus far:
def main():
'''Average grades entered by the user'''
total = 0#Set the total to 0
grade_count = 0#Set the grade count to 0
grade = int(input('Enter grade :'))#Get a grade
while grade != 'quit' or grade != 'Quit':#While the grade is not "quit" or "Quit"
total += grade# Add the grade to total
grade_count += 1# Add one to the grade count
grade = int(input('Enter grade :'))# Get a grade
average = total / grade_count#Average the grades
round(average, 2)#Round the average to two decimal places
print(average)#Print the average
main() #Start execution
And this is the error I am getting:
Enter grade :70
Enter grade :80
Enter grade :90
Enter grade :quit
Traceback (most recent call last):
File "\\trace\Class\CSC-130\004\Rall992\Asn2\Asn2-1.py", line 21, in <module>
main() #Start execution
File "\\trace\Class\CSC-130\004\Rall992\Asn2\Asn2-1.py", line 16, in main
grade = int(input('Enter grade :'))# Get a grade
ValueError: invalid literal for int() with base 10: 'quit'