为什么它不允许我打印 "player 1 is x"
why does it not allow me to print "player 1 is x"
我无法打印('player 1 is x')。我做错了什么。
def marker():
mark = ''
while mark != 'x' and mark != "o":
mark = input('select x or o:')
if mark == 'x':
print("player 1 is x")
这对我有效。你 运行 这是和 Python 3 口译员一起吗?
如果你 运行 它与 Python 2.7,input()
你需要在你的字符串输入周围加上引号,因为 eval()
在输入上被调用, 在幕后。否则,它会将您的输入解释为名称。有关更多信息,请参阅 here。
与 Python 2.7:
select x or o:"x"
player 1 is x
与Python3:
select x or o:x
player 1 is x
只是为了涵盖所有基础,您稍后会调用此 marker
函数,对吗?
def marker():
mark = ''
while mark != 'x' and mark != "o":
mark = input('select x or o:')
if mark == 'x':
print("player 1 is x")
marker() # <---
它会给你带来任何错误吗?我 运行 在我的本地机器上使用 Python 3.7 解释器,在调用方法 marker() 后它工作正常。
我无法打印('player 1 is x')。我做错了什么。
def marker():
mark = ''
while mark != 'x' and mark != "o":
mark = input('select x or o:')
if mark == 'x':
print("player 1 is x")
这对我有效。你 运行 这是和 Python 3 口译员一起吗?
如果你 运行 它与 Python 2.7,input()
你需要在你的字符串输入周围加上引号,因为 eval()
在输入上被调用, 在幕后。否则,它会将您的输入解释为名称。有关更多信息,请参阅 here。
与 Python 2.7:
select x or o:"x"
player 1 is x
与Python3:
select x or o:x
player 1 is x
只是为了涵盖所有基础,您稍后会调用此 marker
函数,对吗?
def marker():
mark = ''
while mark != 'x' and mark != "o":
mark = input('select x or o:')
if mark == 'x':
print("player 1 is x")
marker() # <---
它会给你带来任何错误吗?我 运行 在我的本地机器上使用 Python 3.7 解释器,在调用方法 marker() 后它工作正常。