Sep-28-2019, 11:29 AM
As buran pointed out - never use sum as variable name. I would add - never use Python as typing machine. You should see the pattern in ISBN check number calculation: every second number in ISBN is multiplied with 3. So no need to do all this manual labor:
>>> s = '978-0-306-40615' >>> nums = (int(num) for chunk in s.split('-') for num in chunk) # remove '-' and convert into int >>> calculated = (v if i % 2 == 0 else v * 3 for i, v in enumerate(nums)) # keep in mind that Python is 0-indexed >>> last = 10 - sum(calculated) % 10 >>> last 7
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.