I'm trying to calculate the check digit for an ISBN input on python. so far I have...
def ISBN():
numlist = []
request = raw_input("Please enter the 10 digit number: ")
if len(request) == 10:
**numlist == request
print numlist**
if len(request) != 10:
print "Invalid Input"
ISBN()
ISBN()
The bold bit is where im having trouble, I cant seem to split the 10 digit input into individual numbers in the list (numlist) and then multiply the seperated individual numbers by 11 then the next by 10 then the next by 9 etc... For the next part of the program, I will need to add these new multiplied numbers in the list together, then i will use the mod(%) function to get the remainder then subtract the number from 11, any assistance with any of my coding or incorrect statements on how to calculate the ISBN would be greatly appreciated. Thank you.
This code should get you on your way:
Strings are iterable, so if you iterate them, each element is returned as a single-character string.
int
builds an int from a (valid) string.The notation
[a*b for a,b in zip(listofnums, multipliers)]
is a list comprehension, a convenient syntax for mapping sequences to new lists.As to the rest, explore them in your repl. Note that
reversed
returns a generator: if you want to see what is "in" it, you will need to usetuple
orlist
to force its evaluation. This can be dangerous for infinite generators, for obvious reasons.I believe
list()
is what you are looking for.numlist=list(request)
Here is how I would write the code. I hope I'm interpreting the code correctly.