简体   繁体   English

ISBN程序的Python属性错误

[英]Python Attribute error with ISBN program

I've just fixed my ISBN checkdigit code to be a bit more efficient, but now it's coming back with an attribute error: 我刚刚将我的ISBN校验码代码固定为更有效,但现在又返回了属性错误:

AttributeError: 'int' object has no attribute 'append'

Here's the code: 这是代码:

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)

Thanks a lot 非常感谢

You have not declared your results to be a list. 您尚未将results声明为列表。 It should be results = [] . 应该是results = [] It is currently results = 0 which makes it an int and hence the append operation fails with an AttributeError 当前results = 0 ,这使其成为一个int ,因此append操作失败,并出现AttributeError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM