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 = []
grades2 = (input(prompt).strip())
length = len(grades)
while (grades2 != "quit"):
grades.append(grades2)
grades2 = input(prompt).strip()
if (grades2 == "quit"):
average = float(sum(grades)/len(grades))
print (name1, name2, average)
だから私はプログラムが平均私を印刷しようとしていると私はこのエラーを取得:平均
Traceback (most recent call last):
File "C:/Users/Owner/AppData/Local/Programs/Python/Python35/Project.py", line 13, in <module>
average = float(sum(grades)/len(grades))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
ヘルプを!
"入力" メソッドの2番目の最後の行は、文字列のみを返します。整数を返すには、 "int(input(prompt))" –