我正在制作一个ISBN程序来解决校验位,我想让它在程序为您找到校验位时打开一个新的字符串,说“你想不想关闭程序”,我已经这样做了。在
如果有人说“n”表示不,它会返回到开头,如果这个人说“y”,程序关闭,我就卡住了,开始搜索互联网,我的代码在下面,有人能帮我调整一下吗?谢谢。在
这是我的代码:
ISBN=input("Please enter a 10 digit number for the ISBN check digit: ")
while len(ISBN)!= 10:
print("Please try again and make sure you entered 10 digits.")
ISBN=int(input("Please enter the 10 digit number again: "))
continue
else:
D1 =int(ISBN[0])*11
D2 =int(ISBN[1])*10
D3 =int(ISBN[2])*9
D4 =int(ISBN[3])*8
D5 =int(ISBN[4])*7
D6 =int(ISBN[5])*6
D7 =int(ISBN[6])*5
D8 =int(ISBN[7])*4
D9 =int(ISBN[8])*3
D10=int(ISBN[9])*2
Sum=(D1+D2+D3+D4+D5+D6+D7+D8+D9+D10)
Mod=Sum%11
D11=11-Mod
if D11==10:
D11='X'
ISBNNumber=str(ISBN)+str(D11)
print("Your 11 digit ISBN Number is *" + ISBNNumber + "*")
def close():
close=input ("would you like to close the program or try again 'y' for Yes and 'n' for No:")
while len(close)==1:
if input == "n":s
return (ISBN)
elif input == "y":
exit()
close()#
这将在代码中添加一个for循环
其他:
最简单的方法是将所有内容包装在
while
循环中:这将每次循环,除非用户输入
'n'
(或类似内容)。注:lower
和{更广泛地说,我认为您的算法有问题;ISBN-10数字的第10个字符(校验位)是根据前9个字符:http://en.wikipedia.org/wiki/Check_digit#ISBN_10计算的。在
相关问题 更多 >
编程相关推荐