CHECKING THE VALIDITY OF AN ISBN
INTERNATIONAL STANDARD BOOK NUMBER (ISBN) is a numeric commercial book identifier which all are different with respect to the books. By this ISBN code, the books are published by the publisher... My program is to check whether a given ISBN is valid or not...
A valid ISBN is a code in which the summation of the digits multiply to it's respective position number is equal to a number which is divisible by 11.
ex:-8174506292 is a valid ISBN
(8*1)+(1*2)+(7*3)+(4*4)+(5*5)+(0*6)+(6*7)+(2*8)+(9*9) +(2*10) =231
#which is divisible by 11#
#Nailed it !!!#
Let's see the code behind it..
def isbn(num):
dig=len(str(num))
temp=num
s=0
while temp>0:
d=temp%10
s=s+(d*dig)
temp=temp//10
dig=dig-1 if s%11==0:
print("Valid ISBN")
else:
print("Invalid ISBN")
num=int(input("enter your book's ISBN")
isbn(num)
OUTPUT
enter your book's ISBN:-8174506314
Valid ISBN
enter your book's ISBN:-8256371896
Invalid ISBN
Great job
ReplyDeleteThanks 😊
Delete