Advertisement
trds

classISBN

Feb 6th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. class ISBN:
  2.     def __init__(self,s):
  3.         if len(s)==13:
  4.             self.isbn=s
  5.         else:
  6.             raise Exception ("ISBN invalid")
  7.  
  8.     def __repr__(self):
  9.         return "ISBN" + str(self.isbn)
  10.  
  11.     def validare (self):
  12.         d1 = int(self.isbn[0])
  13.         d2 = int(self.isbn[1])
  14.         d3 = int(self.isbn[2])
  15.         d4 = int(self.isbn[3])
  16.         d5 = int(self.isbn[4])
  17.         d6 = int(self.isbn[5])
  18.         d7 = int(self.isbn[6])
  19.         d8 = int(self.isbn[7])
  20.         d9 = int(self.isbn[8])
  21.         d10 = int(self.isbn[9])
  22.         d11 = int(self.isbn[10])
  23.         d12 = int(self.isbn[11])
  24.         d13 = int(self.isbn[12])
  25.         d13b = 10 - (d1 + 3*d2 + d3 + 3*d4 + d5 + 3*d6 + d7 + 3*d8 + d9 + 3*d10 + d11 + 3*d12) % 10
  26.         if d13b==10:
  27.             d13b==0
  28.         if d13==d13b:
  29.             return True
  30.         else:
  31.             return False
  32.  
  33. i1 = ISBN ("9789734722211")
  34. i2 = ISBN ("9780470121672")
  35.  
  36. print(i1.validare())
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement