Advertisement
trds

Untitled

Feb 6th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. class ISBN:
  2.     def __init__(self,s):
  3.         if len(s)==10:
  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.         d10b = 10 - (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11
  23.         if d10b==10:
  24.             d10b==0
  25.         if d10==d10b:
  26.             return True
  27.         else:
  28.             return False
  29.  
  30. i1 = ISBN ("0198526636")
  31. i2 = ISBN ("1861972717")
  32.  
  33. print(i1.validare())
  34. print(i2.validare())
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement