-1

我刚刚修复了我的 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)

非常感谢

4

1 回答 1

2

你还没有宣布你results是一个列表。应该是results = []。它是当前results = 0使它成为一个int,因此append操作失败并出现 AttributeError

于 2014-04-03T17:00:46.020 回答