0

I'm just starting to learn python and i'm attempting to do the basic task of building a tic tac toe game. I'm having trouble returning the correct print string and I can't figure out why. I think it has something to do with my "or" statement. I'm trying not to look at the tutorials if I can avoid them.

def playerinput():

    while True: 
        var = raw_input('What marker would you like? (X or O): ')
        if var in ('X', 'O', 'x','o'): 
            break
        print 'Invalid input.'
    if var == 'X' or 'x':
        print 'You have chosen X!'
    else:
        print 'You have chosen O!'

When I type in 'O' or 'o' to the raw_input popup it returns 'You have chosen X!'. I can't figure out what's wrong with my code.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • You're if statement has to be given like this: `if var == 'X' or var == 'x':` – andraiamatrix Jun 23 '16 at 15:52
  • 3
    *"I'm trying not to look at the tutorials if I can avoid them"* - maybe you should reconsider that tactic (or, at least, reevaluate when you can avoid tutorials to not include *"before asking a SO question"*!) – jonrsharpe Jun 23 '16 at 15:52

0 Answers0