Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不断获取TypeError:';int';对象不可下标_Python_Shell_Python 3.x_Pseudocode - Fatal编程技术网

Python 不断获取TypeError:';int';对象不可下标

Python 不断获取TypeError:';int';对象不可下标,python,shell,python-3.x,pseudocode,Python,Shell,Python 3.x,Pseudocode,我正在尝试将该伪代码翻译成Python。以下是伪代码: 伪代码: FOR Count <- 1 TO 13 DO OUTPUT "Please enter next digit of ISBN: " INPUT ISBN[Count] ENDFOR CalculatedDigit <- 0 Count <- 1 WHILE Count < 13 DO CalculatedDigit <- CalculatedDigit + ISBN[Count] C

我正在尝试将该伪代码翻译成Python。以下是伪代码:

伪代码:

FOR Count <- 1 TO 13 DO
  OUTPUT "Please enter next digit of ISBN: "
  INPUT ISBN[Count]
ENDFOR
CalculatedDigit <- 0
Count <- 1
WHILE Count < 13 DO
  CalculatedDigit <- CalculatedDigit + ISBN[Count]
  Count <- Count + 1
  CalculatedDigit <- CalculatedDigit + ISBN[Count] * 3
  Count <- Count + 1
ENDWHILE
WHILE CalculatedDigit >= 10 DO
  CalculatedDigit <- CalculatedDigit - 10
ENDWHILE
CalculatedDigit <- 10 - CalculatedDigit
IF CalculatedDigit = 10
  THEN CalculatedDigit <- 0
ENDIF
IF CalculatedDigit = ISBN[13]
  THEN OUTPUT "Valid ISBN"
  ELSE OUTPUT "Invalid ISBN"
ENDIF
for Count in range(1,13):
  print("Please enter next digit of ISBN:")
  ISBN = int(input(">"))
  ISBN[Count]
CalculatedDigit = 0
Count = 1
while Count < 13:
  CalculatedDigit = CalculatedDigit + ISBN
  Count = Count + 1
  CalculatedDigit = CalculatedDigit + ISBN * 3
  Count = Count + 1
while CalculatedDigit >= 10:
  CalculatedDigit = CalculatedDigit - 10
  CalculatedDigit = 10 - CalculatedDigit
if CalculatedDigit == 10:
  CalculatedDigit = 0
if CalculatedDigit == ISBN[13]:
  print("Valid ISBN")
else:
  print("Invalid ISBN")
用于计数
ISBN
是一个整数

ISBN[Count]
正在尝试访问ISBN的位置
Count
。但你不能,因为整数是不可下标的

如何取而代之:

ISBN = list(map(int, input('Please enter full ISBN: ')))
ISBN现在是一个整数列表,应该可以像您预期的那样工作。

ISBN不是数组

数组:
ISBN=[1,2,3,4]

访问阵列:
ISBN[2]
将返回
3

你到底想用它做什么?

仔细想想

a = 5
print(a[1])
你希望这个打印出来什么


数字不是列表。通过使用
[]
s,您试图访问对象中包含的内容,但int不包含任何内容!它们只是数字

代码中还有其他类似的错误:
如果CalculatedDigit==ISBN[13]:
@AnasYusef我将其编辑到我的帖子中。刷新页面我正在尝试翻译我刚才添加的伪代码。抱歉给您带来不便您想做什么?你认为问题出在哪里?你试过什么?另请参阅:另外,在许多情况下,尝试做一个极小的()示例通常有助于在您的on上找到答案。ISBN是书籍的序列号。他们有一个支票数字。他试图验证ISBN的数字
a = 5
print(a[1])