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 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