Answer:
is_isbn = True
total = 0
number = input("Enter the ISBN: ")
if len(number) != 10:
is_isbn = False
for i in range(9):
if 0 <= int(number[i]) <= 9:
total += int(number[i]) * (10 - i)
else:
is_isbn = False
if number[9] != 'X' and int(number[9]) > 9:
is_isbn = False
if number[9] == 'X':
total += 10
else:
total += int(number[9])
if total % 11 != 0:
is_isbn = False
if is_isbn:
print("It is a valid ISBN")
else:
print("It is NOT a valid ISBN")
Step-by-step explanation:
Initialize the variables, total and is_isbn - keeps the value for the number if it is valid or not
Ask the user for the ISBN number
If number's length is less than 10, it is not valid, set is_isbn to false
Then, make calculation to verify the ISBN
Check the last digit, if it is not "X" and greater than 10, it is not valid, set is_isbn to false
Again, check the last digit, if it is "X", add 10 to the total, otherwise add its value
Check if total can divide 11 with no remainder. If not, it is not valid, set is_isbn to false
Finally, depending on the is_isbn variable, print the result