-2

so I have this code right here for a tic tac toe program

def playerID():
    # asks player if want x or y
    letter = ''
    while not (letter == 'X' or letter == 'O'):
        letter = input('Do you want to be X or O?').upper()

    # first tuple is player, second is computer
    if letter == 'X':
        return ['X', 'O']
    else:
        return ['O', 'X']

and the second half of the code is

while True:
    # resets the board
    theBoard = [' '] * 10
    playerLetter, computerLetter = playerID()
    turn = playFirst()
    print('The ' + turn + ' will go first.')

it continues on after that but it's giving me two error's. I don't think it's case sensitive. I'm not so good with strings or arrays, could someone point what I'm doing wrong here?

I think this is a problem with the call back, but of course I could just be talking out of my butt.

  • You are using Python 2.x in which `input` evaluates strings. Your code is trying to evaluate the string 'X' and failing to do so because you haven't initialized a variable named X. You probably want `raw_input`. Also why is your board of size 10? – Shashank May 12 '15 at 00:33
  • alright that would explain a lot of the problems I've been having. My program has been using input the entire time and raw_input apperantly works better. Also I don't know why I put 10, I just put a number down and once I got it working I would've made it better looking. – Emmett Thorne May 12 '15 at 00:37
  • In the future, don't post your errors as pictures in imgur. Copy paste the errors here, it helps S.O. people a lot. – Shashank May 12 '15 at 00:43
  • alright, thanks. I'll make note of it for the future. What does S.O. mean? Also your solution fixed all the problems I was having and the program is successfully running so kudos to you! – Emmett Thorne May 12 '15 at 01:14
  • S.O. = Stack Overflow, you should accept an answer below by clicking on the checkmark to the left of it. – Shashank May 12 '15 at 01:21

1 Answers1

3

you should use raw_input instead of input to get a string values in python 2.x

Dzarafata
  • 558
  • 3
  • 11