-3
コーディング中にこのエラーが発生しましたが、その意味がわかりません。サポートされていないオペランドタイプのエラーが表示されるのはなぜですか?
line 59, in <module>
filename=class_name + ".csv"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
私は私が台無しにどこか分からないが、それはクラス番号の検証を行うことであるかもしれません。
while True:
try:
class_name=int(input("Are you in class 1, 2 or 3? "))
if class_name in [1, 2, 3]:
print(name,", welcome to this maths test!")
break
else:
print ("Class has to be 1, 2 or 3")
except ValueError:
print ("Class has to be 1, 2 or 3")
filename=class_name + ".csv"
with open(filename, 'a') as f:
f.write(str(name) + " : " + str(score) + '\n')
if results("Do you wish to view previous results for your class? (yes or no) "):
with open(filename, 'r') as f:
print(f.read())
'CLASS_NAME 'を入力時に' int'に変換するので、 'int'型です。 '' .csv "'は 's'str'型です。 'filename = str(class_name)+" .csv "または' filename = "{} .csv" .format(class_name) ' – dwanderson