ISBN check digit solver, user feedback

老子叫甜甜 提交于 2019-11-28 02:30:19

The easiest way is to wrap everything in a while loop:

while True:
    # ... put all your code here
    close = input("Would you like to try again? Enter 'y' for Yes and 'n' for No: ")
    if close.lower() in ("n", "no"):
        print("Exiting")
        break

This will loop each time, unless the user enters 'n' (or similar). Note:

  1. Clearer question, with an explicit yes or no answer; and
  2. Use of lower and in to allow range of possible valid inputs.

More broadly, I think you have problems with your algorithm; the 10th character (check digit) for an ISBN-10 number is calculated based on the first nine: http://en.wikipedia.org/wiki/Check_digit#ISBN_10.

This adds a for loop in to your code

else:

Sum = 0
for i in range(len(isbn)):
    sum= int(isbn[i])
mod=sum%11
digit11=11-mod
if digit11==10:
   digit11='X'
iSBNNumber=str(isbn)+str(digit11)
print('Your 11 digit ISBN Number is ' + iSBNNumber)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!