TypeError:在Tic-Tac-Toe游戏-Python 3.2中,列表索引必须是整数?

TypeError:在Tic-Tac-Toe游戏-Python 3.2中,列表索引必须是整数?,python,pygame,typeerror,tic-tac-toe,Python,Pygame,Typeerror,Tic Tac Toe,所以我在做一个井字游戏时遇到了很多问题,但我找到了解决大部分问题的方法。但现在的问题是,我得到了一个错误的阅读 Traceback (most recent call last): File "/Users/user/Desktop/tic tac toe game.py", line 43, in <module> if board[input] != 'x' and board[input] !='o': TypeError: list indices must be

所以我在做一个井字游戏时遇到了很多问题,但我找到了解决大部分问题的方法。但现在的问题是,我得到了一个错误的阅读

Traceback (most recent call last):
  File "/Users/user/Desktop/tic tac toe game.py", line 43, in <module>
    if board[input] != 'x' and board[input] !='o':
TypeError: list indices must be integers, not builtin_function_or_method" 

我不知道该做什么,我喜欢周四刚开始的python,对它不是很在行。。但是感谢所有的帮助(:哦,我有python 3.2。

看起来
input
在这里不是整数,您在这里使用了
input()
,这是一个内置函数。 永远不要将
input
用作变量名

查看相同错误:

>>> a=[1,2,3,4]
>>> a[input]

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    a[input]
TypeError: list indices must be integers, not builtin_function_or_method

一个坏的变量名的例子,我想……好吧。但是现在它说“回溯(最近一次调用):File”/Users/user/Desktop/tic tac toe game.py”,第43行,在if Board[int(n)]!='x'和Board[int(n)]!='o::name错误:没有定义名称“Board”,我决定将“Board”改为“Board”这个错误消失了&然后它出现了这个错误-回溯(最后一次调用):文件“/Users/user/Desktop/tic tac toe game.py”,第43行,在if board[int(n)]!='x'和board[int(n)]!='o':名称错误:名称'n'不正确defined@AliLewis我只是在这里使用了一个示例代码,因为我不知道您的代码是什么样子,也不知道您定义了哪个变量。我使用了一些代码中可能不存在的变量(例如
n
).我很困惑..我只需要找到新的代码并修复它。我非常渴望完成这个游戏):你遇到的每个错误基本上都是一样的。请学习阅读错误信息,并使用自己的代码仔细交叉引用。在编写
int(n)
时,必须首先解释
n
是什么<代码>N不同。类似的
board
board
>>> a=[1,2,3,4]
>>> a[input]

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    a[input]
TypeError: list indices must be integers, not builtin_function_or_method
>>> Board=['a','x','o','b','c','d']
>>> n=input()#input returns a string,not integer
2
>>> if Board[int(n)]!='x' and Board[int(n)]!='o': #list expect  only integer indexes,convert n to integer first using
    Board[int(n)]='x'


>>> Board
['a', 'x', 'o', 'b', 'c', 'd']