Checking if an ISBN number is correct

前端 未结 8 1740
臣服心动
臣服心动 2020-12-28 20:43

I\'m given some ISBN numbers e.g. 3-528-03851 (not valid) , 3-528-16419-0 (valid). I\'m supposed to write a program which tests if the ISBN number

8条回答
  •  既然无缘
    2020-12-28 21:09

    Your check digit can take on the values 0-10, based on the fact that it's modulo-11. There's a problem with the line:

        check_digit = int(isbn[-1]) 
    

    as this works only for the digits 0-9. You'll need something for the case when the digit is 'X', and also for the error condition when it isn't any of the above - otherwise your program will crash.

提交回复
热议问题