[英]why does it not allow me to print "player 1 is x"
我无法打印('玩家 1 是 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()
。 否则,它会将您的输入解释为名称。 看这里了解更多。
使用 Python 2.7:
select x or o:"x"
player 1 is x
使用 Python 3:
select x or o:x
player 1 is x
只是为了涵盖所有基地,您稍后将此marker
称为 function,对吗?
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() 后它工作正常。
我无法打印('玩家 1 是 x')。 我究竟做错了什么。
def marker():
mark = ''
while mark != 'x' and mark != "o":
mark = input('select x or o:')
if mark == 'x':
print("player 1 is x")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.