y=''
print 'y= nothing'
y = raw_input('-->')
while y!='O' or y!='X':
print 'You have to choose either X or O'
y = raw_input('-->')
print 'Loop exited'
print y
Could anyone explain why the above code doesn't run properly in python?
I assume that any time the user inputs something except 'X' or 'O' he gets the message and the prompt for input. But as soon as the user provides either 'X' or 'O', the loop should exit. But it doesn't... Could you, guys help? I am a novice in python...
andinstead oforfor your while loop.not (y=='O' and y=='X'), y cannot equals to two different char. Soy=='O' and y=='X'is alwaysFalse, and thennot (y=='O' and y=='X')is alwaysTrue. I think what you want isy!='O' and y!='X'.yis equal to'O'or'X'.