Your problem is that your appending strings to your list, instead of numbers. You need to cast your user input to an integer before appending them to your list. You can see this by printing your list on each iteration of your while loop:
Please enter in your first name :dummy
Please enter in your last name :name
Please enter in your grades. When you are finished, enter 'quit': 1
[]
Please enter in your grades. When you are finished, enter 'quit': 2
['1']
Please enter in your grades. When you are finished, enter 'quit': 3
['1', '2']
Please enter in your grades. When you are finished, enter 'quit': 4
['1', '2', '3']
Please enter in your grades. When you are finished, enter 'quit': 5
['1', '2', '3', '4']
Please enter in your grades. When you are finished, enter 'quit': 6
['1', '2', '3', '4', '5']
Please enter in your grades. When you are finished, enter 'quit':
Also, you should check your user input to see if it equals the string "quit"
before appending it to your grades
list so that it is not appended to the list:
name1 = input("Please enter in your first name :")
name2 = input("Please enter in your last name :")
prompt = "Please enter in your grades. When you are finished, enter 'quit': "
grades = []
while True:
grade = input("Enter a grade: ")
if grade == "quit":
average = sum(grades) / len(grades)
print(name1, name2, average)
break
grades.append(int(grade))
Changes:
- I used a while-true instead of a while condition because there is no need to test your user input in your while loop as well as your if statement.
- I added the check to see if the user quits before you append the user input to your
grades
list.
- I cast the user input to an integer before appending it to your
grades
list.