python - 检查 ISBN 书号是否有效 Python

标签 python

所以我一直在尝试将这个“验证器”从伪代码转换为Python,但我不太确定我的值是否被放入列表中。输入第一个值后,出现错误:'int' object is not callable。但是,如果我删除 isbn = mylist(),它会说 name 'isbn' 未定义。有人能指出我的错误在哪里吗?

我很确定我没有正确设置列表。

这是我正在关注的伪代码:

enter image description here

我的代码:

def checkDigit():
    calculateDigit = 0
    count = 1
    calculateDigit = 10 - calculateDigit
    for count in range (1,14):
        mylist = int(input("Please enter the next digit of the ISBN: "))
 #      isbn = mylist()
    while (count <= 13):
        calculateDigit = calculateDigit + isbn[count]
        count = count + 1
        calculateDigit = calculateDigit + (isbn[count] * 3)
        count = count + 1
    while (calculateDigit >= 10):
        calculateDigit = calculateDigit - 10
    if (calculateDigit == 10):
        calculateDigit = 0
    if (calculateDigit == isbn[13]):
        print ("Valid ISBN")
    else:
        print ("Invalid ISBN")



checkDigit()

最佳答案

您收到该错误是因为您将 int 分配给 mylist,然后调用它。这相当于类似

>>>5() # 'int' object is not callable error

尝试像字符串一样设置你的 isbn

isbn = ""
    for count in range (1,14):
    mylist = int(input("Please enter the next digit of the ISBN: "))
    isbn += mylist

或者像这样的数字列表

isbn = []
    for count in range (1,14):
    mylist = int(input("Please enter the next digit of the ISBN: "))
    isbn.append(mylist)

关于python - 检查 ISBN 书号是否有效 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36335220/

相关文章:

python - 类似于 OS X 上的 pyHook

python - 从 SHA-1 恢复损坏的 128 位 key

python - python mongodb gridfs "no file"错误

python - 新类实例未初始化

python - 如何让 NumPy 打印尾随 0?

python - 扫描安全的 pdf 文档

python - 尝试替代 xpath,否则继续

python - 通过 python 进行多人游戏

python - 如何使用Python在excel上打印开始时间和结束时间?

python - 使用 VirusTotal API 扫描文件