I am getting really tired, so I am probably doing something dumb(disclaimer). below is a python function I am trying to test

# answer.py
# this function asks for a move and checks to see 
# if it is a legal place to choose.

position = ['X','O',' ',' ',' ',' ',' ',' ',' '] # this line is for testing only

def answer():
    guess = int(raw_input("please enter your move(enter here)"))
    while guess - 1 not in range(9):
	guess = int(raw_input("please enter a number chosen from 1-9(enter here)"))
    while True:
        if position[guess -1] in ('X', 'O'):
	    guess = int(raw_input("\nplease enter a different move, that space is already occupied(enter here)"))
    #return position[guess -1]
    return 'hhhhh' # I added this return code to simply it 


print answer()

this line below should run the function


here is where I am screwing something up. I thought the following line of code would print the return value. but it just seems to rerun the function once, then print the return vaue, why is it rerunning the function?

print answer()

isn't that the correct way to print a return value?

13 Years
Discussion Span
Last Post by shanenin

I should go to bed. I see why it was screwing up(at least I thought it was).

the second
print answer() will rerun the function. For some crazy reason, I was thinking it could give the return value without rerunning it again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.