Sep-28-2019, 11:43 AM
(Sep-28-2019, 11:01 AM)kumaaaa Wrote:(Sep-28-2019, 09:38 AM)Gribouillis Wrote: You need to convertThanks for your reminder.isbn[12]
to int as well.if int(isbn[12]) == 0: ... if int(isbn[12]) == ...: ...
(Sep-28-2019, 09:14 AM)kumaaaa Wrote: This is a code i made that checks whether an isbn with 13 digits is valid, but there is something wrong but I don't know what it is. The principle is like this for example, 978-0-306-40615-? is calculated as follows: sum = 9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3 = 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15 = 93 93 / 10 = 9 remainder 3 10 – 3 = 7 Thus, the check digit is 7, and the complete sequence is ISBN 978-0-306-40615-7. if the sum is divisble by 10, the remainder will be zero and 10-0=10, however, the check digit is still 0. However in the code, when I check 9781491939369, which is a valid isbn, it outputs invalid.Thank you very much.isbn=input('ISBN: ') sum=(1*int(isbn[0])+3*int(isbn[1])+1*int(isbn[2])+3*int(isbn[3])+1*int(isbn[4])+3*int(isbn[5])+1*int(isbn[6])+3*int(isbn[7])+1*int(isbn[8])+3*int(isbn[9])+1*int(isbn[10])+3*int(isbn[11])) if sum%10==0: if isbn[12]==0: print('Valid') else: print('Invalid') else: if isbn[12]==10-(sum%10): print('Valid') else: print('Invalid')Thanks a lot.
Thank you