打印分数时显示错误
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)
行
score = len([])
使用len
函数,该函数返回指定列表的整数(int)长度。在python中,整数不能被追加,就像您试图在末尾追加分数时所做的那样。也许您打算做的是添加到分数中,语法是score = score + 1
,速记版本是score += 1
相关问题 更多 >
编程相关推荐