我用下面的代码玩井字游戏。但是,当我运行它时,我得到一个错误:
PS C:\python33> python tictactoe.py
Welcome to Tic Tac Toe!
Do you want to be X or O?
0
Traceback (most recent call last):
File "tictactoe.py", line 145, in <module>
playerLetter, computerLetter = inputPlayerLetter()
File "tictactoe.py", line 27, in inputPlayerLetter
letter = input().upper()
File "<string>", line 1, in <module>
NameError: name 'x' is not defined
PS C:\python33>
我尝试过将第27行的字母改为字符串,但这并不能解决问题。我尝试过的其他线程似乎没有那么有用。这是我following的代码。我使用的是python3.3。在
^{pr2}$
看来你的问题是:
您告诉python尝试理解您输入的字符串。根据您的描述,您可能正在寻找
^{pr2}$raw_input()
。 测试示例:raw_input()
返回的'x'
是一个字符串,它支持upper()
相关问题 更多 >
编程相关推荐