-1

I've just fixed my ISBN checkdigit code to be a bit more efficient, but now it's coming back with an attribute error:

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 should learn to solve problems like this yourself. Instead of thinking 'help! it displays an attribute error! better post that question to SO!', think about __why__ it displays the error. The error message even tells you why: Because the object is an int. Why is it an int? Do you want it to be an int? What should it be instead? – mic_e Apr 03 '14 at 17:10
  • Sorry, I panicked a little, I'll do this next time – user3143129 Apr 03 '14 at 17:15
  • This is just the issue that an intermediate or experienced programmer faces constantly, maybe a few times an hour, and resolves by just reading the error message and thinking about it a tiny bit. If you want to do a bigger project (> 100 lines of code), it simply isn't feasible to ask on SO for every single minor error that can be resolved with a minimum amount of own thinking. – mic_e Apr 03 '14 at 23:17

1 Answers1

2

You have not declared your results to be a list. It should be results = []. It is currently results = 0 which makes it an int and hence the append operation fails with an AttributeError

shaktimaan
  • 11,962
  • 2
  • 29
  • 33