我刚刚修复了我的 ISBN 校验位代码以提高效率,但现在它返回了一个属性错误:
AttributeError: 'int' object has no attribute 'append'
代码如下:
isbn = 0
result = 0
results = 0
print("Please input your ISBN 1 number at a time")
isbn = [int(input("ISBN character {0}: ".format(i)))
for i in range(1, 11)]
results.append(isbn[0] * 11)
results.append(isbn[1] * 10)
results.append(isbn[2] * 9)
results.append(isbn[3] * 8)
results.append(isbn[4] * 7)
results.append(isbn[5] * 6)
results.append(isbn[6] * 5)
results.append(isbn[7] * 4)
results.append(isbn[8] * 3)
results.append(isbn[9] * 2)
enter code here
results = sum(results)
result = results % 11
result = 11 - result
result = str(result)
if result == "10":
result = "X"
print("Your ISBN is '",
isbn[range(10)],result,"'")
print("The checksum is",result)
多谢
您尚未将results
声明为列表。应该是results = []
.它当前results = 0
,这使它成为一个int
,因此append
操作失败并显示 AttributeError