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