[英]Checking if an ISBN Book Number is valid Python
So I have been trying to convert this 'validator' from Pseudocode to Python, but I'm not too sure if my values are being put into a list.所以我一直在尝试将这个“验证器”从伪代码转换为 Python,但我不太确定我的值是否被放入列表中。 After I enter the first value, an error appears saying: 'int' object is not callable
.输入第一个值后,出现错误提示: 'int' object is not callable
。 But then if I get rid of isbn = mylist()
, it says that name 'isbn' is not defined
.但是如果我去掉isbn = mylist()
,它会说name 'isbn' is not defined
。 Can someone point me out where my mistake is?有人可以指出我的错误在哪里吗?
I'm pretty sure I'm not setting up my list correctly.我很确定我没有正确设置我的列表。
Here is the PSEUDOCODE I'm following:这是我正在关注的伪代码:
And my code:还有我的代码:
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()
youre getting that error because you assign an int to mylist, and then call it.您收到该错误是因为您将 int 分配给 mylist,然后调用它。 This is equivalent to something like这相当于
>>>5() # 'int' object is not callable error
try setting up your isbn like so for a string尝试像这样为字符串设置你的 isbn
isbn = ""
for count in range (1,14):
mylist = int(input("Please enter the next digit of the ISBN: "))
isbn += mylist
or like this for a list of numbers或者像这样的数字列表
isbn = []
for count in range (1,14):
mylist = int(input("Please enter the next digit of the ISBN: "))
isbn.append(mylist)
mylist is an integer, you can't perform a mylist() operation mylist 是一个整数,你不能执行 mylist() 操作
I think what you intend to do is isbn.append(mylist)
so when the loop ends you have all the items stored in isbn我认为您打算做的是isbn.append(mylist)
所以当循环结束时,您将所有项目都存储在 isbn 中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.