ISBN程序的Python属性错误

时间:2014-04-03 16:59:48

标签: python isbn check-digit

我刚刚修复了我的ISBN checkdigit代码以提高效率,但现在它又出现了属性错误:

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)

非常感谢

1 个答案:

答案 0 :(得分:2)

您尚未声明自己的results是列表。它应该是results = []。它目前为results = 0,使其为int,因此append操作失败并出现AttributeError