[Tutor] HELP!!!!!

Chris Calloway cbc at unc.edu
Thu Apr 17 17:07:21 CEST 2008


On 4/17/2008 3:40 AM, Michael Kim wrote:
> Hi I am having a really hard time making my tictactoe program work.  I 
> was wondering if you could could check it out and help me with the 
> error.  Thanks

Heh.

First, there are two obvious indentation errors you can find yourself. 
This may be a byproduct of having pasted your program into an email. 
Email programs will often incorrectly reformat Python code so that the 
indentation no longer works. To send long code listings to an email 
list, use a pastebin like:

http://python.pastebin.com/

and send us the link of your pasted code.

So after you fix the indentation errors, we get this:

 >>> main()
Do you want to go first? (y/n): y
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "<stdin>", line 2, in main
   File "<stdin>", line 4, in pieces
UnboundLocalError: local variable 'X' referenced before assignment
 >>>

And if you look just where the traceback is telling you (line 4 of 
function pieces):

 >>> def pieces():
...     whosefirst=askquestion("Do you want to go first? (y/n): ")
...     if whosefirst == "y":
...         human = X

You see that you did indeed do exactly what the traceback told you. You 
referenced a local variable named X before anything was assigned to X.

Good luck with your homework!

-- 
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599


More information about the Tutor mailing list