im a beginner with python, and I'm having trouble with some functions. I'm pretty sure it might be a syntax error or how i set up the code, since i am a beginner, however, i have no clue why this code works. Here is the code, its for a tic tac toe game in terminal

import random

X = "*"
O = "*"
Player = "*"
Computer = "*"


def inputPlayerLetter():


    if letter == "X":
        print "You are now X's, you will go first"
        Player = "X"
        Computer = "O"
    else:
        print "You are now O's you will go second"
        Player = "O"
        Computer = "X"
    return Player
    return Computer

inputPlayerLetter()

s1 = "*"
s2 = "*"
s3 = "*"
s4 = "*"
s5 = "*"
s6 = "*"
s7 = "*"
s8 = "*"
s9 = "*"

def Board():
    print ""
    print "",s1,"|",s2,"|",s3
    print "","---------"
    print "",s4,"|",s5,"|",s6
    print "","---------"
    print "",s7,"|",s8,"|",s9, "\n"

Board()


def Player1():
    move = raw_input('Choose a space 1-9 \n')

    if move == "1":
    s1 = "X"
    elif move == "2":
        s2 = "X"
    elif move == "3":
        s3 = "X"
    elif move == "4":
        s4 = "X"
    elif move == "5":
        s5 = "X"
    elif move == "6":
        s6 = "X"
    elif move == "7":
        s7 = "X"
    elif move == "8":
        s8 = "X"
    elif move == "9":
        s9 = "X"


def Computer1():
    random.randint(0, 1, 2, 3, 4)

    if random.randint(0, 1, 2, 3, 4) == 0:
    s1 = "X"
    elif random.randint(0, 1, 2, 3, 4) == 1:
        s3 = "X"
    elif random.randint(0, 1, 2, 3, 4) == 2:
        s5 = "X"
    elif random.randint(0, 1, 2, 3, 4) == 3:
        s7 = "X"
    elif random.randint(0, 1, 2, 3, 4) == 4:
        s9 = "X"


Player1()
Board()

if Player == "X":
    Player1()
    Board()
elif Player == "O":
    Computer1()
    Board()

when i run it in terminal, i get this (listed so that the first run i choose X, and the second i choose O, thus the computer is X).

Do you want to be X or O? 
X
You are now X's, you will go first

 * | * | *
 ---------
 * | * | *
 ---------
 * | * | * 

HHNEs-MacBook-Pro-3:ttt hhneadmin$ !!
python ttt.py
Do you want to be X or O? 
O
You are now O's you will go second

 * | * | *
 ---------
 * | * | *
 ---------
 * | * | * 

However, when i have my functions for a player or computer move, their edits to the variables in the Board() don't apply and change the Board(). When the function is called in the if-elif statement at the bottom, why does this have no affect, even though s(number) is redefined from * to X, and then Board() is printed again. Why is this, and is there any way to fix this?

The second return statement in inputPlayerLetter() never executes because the function exits when the first return is called. It should be

return Player, Computer

And you then have to catch the return when you call the function. See "the return Statement" at this link for a tutorial http://www.tutorialspoint.com/python/python_functions.htm
and https://www.safaribooksonline.com/library/view/python-cookbook-3rd/9781449357337/ch07s04.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.