【发布时间】:2014-04-29 21:38:31
【问题描述】:
我正在制作一个 ISBN 校验位程序。然而,虽然我已经让我的程序只接受长度为 10 的值,但如果我输入 10 个字母,它会崩溃。
有谁知道如何解决这个问题?
我的代码:
isbnnumber = input('Please input your 10 digit book no. : ')
while len(isbnnumber) != 10:
print('You have not entered a 10 digit value! Please try again.')
isbnnumber = input('Please input your 10 digit book no. : ')
else:
no1 = int(isbnnumber[0])*11
no2 = int(isbnnumber[1])*10... etc...
非常感谢您的帮助,谢谢。
【问题讨论】:
-
您使用的是 Python 3.x 吗?如果是这样,你应该用'Python-3.x'标记它
-
是的,我会这样做。对这个问题有帮助吗?
-
许多 ISBN 包含字母 X 和数字,任何对数字的字符限制都会在这些 ISBN 上中断。大写 X 表示用作校验位时的数字 10 isbn.org/faqs_general_questions#isbn_faq5
标签: python python-3.x integer isbn