检查ISBN书号是否有效

时间:2016-03-31 13:43:20

标签: python

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

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

以下是PSEUDOCODE:

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()

2 个答案:

答案 0 :(得分:1)

您收到该错误是因为您将一个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)

答案 1 :(得分:1)

mylist是一个整数,你不能执行mylist()操作

我认为您打算做的是isbn.append(mylist)所以当循环结束时,您将所有项目存储在isbn中

相关问题