"int"对象没有名为"append"的属性

2024-04-26 12:04:49 发布

您现在位置: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 = "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)

Tags: oftheanswerinputifiswhatelse
1条回答
网友
1楼 · 发布于 2024-04-26 12:04:49

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

相关问题 更多 >