Python “int”对象没有名为“append”的属性

Python “int”对象没有名为“append”的属性,python,Python,打印分数时显示错误 question1 = input("what is the capital of india ") answer1 = "delhi" print("") question2 = input("what is the capital of telangana ") answer2 = "hyderabad" print("") question3 = input("what is the capital of andhra pradesh ") answer3 = "ama

打印分数时显示错误

question1 = input("what is the capital of india ")
answer1 = "delhi"
print("")
question2 = input("what is the capital of telangana ")
answer2 = "hyderabad"
print("")
question3 = input("what is the capital of andhra pradesh ")
answer3 = "amaraavathi"
print("")
score = len([])
if question1 == answer1 :
        print("correct answer")
        print('')
else :
        print('wrong answer')
        print('')
if question2 == answer2 : 
        print("correct answer")
        print('')
else :
        print("wrong answer")
        print('')
if question3 == answer3 :
        print("correct answer")
        print('')
else :
        print("wrong answer")
        print('')
if question1 == answer1 :
        score.append(3)
else :
        score
if question2 == answer2 :
        score.append(2)
else :
        score
if question3 == answer3 :
        score.append(3)
else :
        score
print(score)

line score=len[]使用len函数,该函数返回指定列表的整数int长度。在python中,整数不能被追加,就像您试图在末尾追加分数时所做的那样。也许您打算做的是添加到分数中,语法为score=score+1,速记版本为score+=1

请至少格式化您的代码…您已将分数设置为等于len[]。所以你把它初始化为0。您需要将其初始化为列表分数=[],然后调用printlenscore以实现您的目标。请始终给出正确的错误描述、完整的错误回溯,并解释您尝试诊断和解决问题的方法。是的,它成功了,谢谢兄弟