Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ISBN:
- def __init__(self,s):
- if len(s)==13:
- self.isbn=s
- else:
- raise Exception ("ISBN invalid")
- def __repr__(self):
- return "ISBN" + str(self.isbn)
- def validare (self):
- d1 = int(self.isbn[0])
- d2 = int(self.isbn[1])
- d3 = int(self.isbn[2])
- d4 = int(self.isbn[3])
- d5 = int(self.isbn[4])
- d6 = int(self.isbn[5])
- d7 = int(self.isbn[6])
- d8 = int(self.isbn[7])
- d9 = int(self.isbn[8])
- d10 = int(self.isbn[9])
- d11 = int(self.isbn[10])
- d12 = int(self.isbn[11])
- d13 = int(self.isbn[12])
- d13b = 10 - (d1 + 3*d2 + d3 + 3*d4 + d5 + 3*d6 + d7 + 3*d8 + d9 + 3*d10 + d11 + 3*d12) % 10
- if d13b==10:
- d13b==0
- if d13==d13b:
- return True
- else:
- return False
- i1 = ISBN ("9789734722211")
- i2 = ISBN ("9780470121672")
- print(i1.validare())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement