def player_input():
marker = ''
while 'X' or 'O' not in marker:
marker = input("Choose between 'X' or 'O': ")
print ("Please choose between 'X' or 'O'")
if marker == 'X':
return ('X', 'O')
else:
return ('O', 'X')
def player_input():
marker = ''
while not (marker == 'X' or marker == 'O'):
marker = input("Choose between 'X' or 'O': ")
print ("Please choose between 'X' or 'O'")
if marker == 'X':
return ('X', 'O')
else:
return ('O', 'X')
我都运行了,但是循环并没有首先停止。两者有什么区别?
答案 0 :(得分:0)
您有缩进错误。 if语句不在循环中。试试这个代码。 while循环仅运行一次,因为您在if语句中使用过else
def player_input():
marker = ''
while not (marker == 'X' or marker == 'O'):
marker = input("Please choose between 'X' or 'O' >")
if marker == 'X':
return ('X', 'O')
else:
return ('O', 'X')
print( player_input() )