Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ISBN:
- def __init__(self,s):
- if len(s)==10:
- 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])
- d10b = 10 - (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11
- if d10b==10:
- d10b==0
- if d10==d10b:
- return True
- else:
- return False
- i1 = ISBN ("0198526636")
- i2 = ISBN ("1861972717")
- print(i1.validare())
- print(i2.validare())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement