Split an integer into digits to compute an ISBN checksum [duplicate]

Just create a string out of it.

myinteger = 212345
number_string = str(myinteger)

That’s enough. Now you can iterate over it:

for ch in number_string:
    print ch # will print each digit in order

Or you can slice it:

print number_string[:2] # first two digits
print number_string[-3:] # last three digits
print number_string[3] # forth digit

Or better, don’t convert the user’s input to an integer (the user types a string)

isbn = raw_input()
for pos, ch in enumerate(reversed(isbn)):
    print "%d * %d is %d" % pos + 2, int(ch), int(ch) * (pos + 2)

For more information read a tutorial.

Leave a Comment