2013-12-06 6 views
0

Я изучаю код в Python и используя IDLE, я поставил этот код, однако, когда я нажал F5, ничего не происходит ... выход не происходит.Любая причина, по которой мой код Python не отображается?

Возможно ли это из-за того, что код, который я вложил, не нуждается в выходе? Или, может быть, я спасу неправильно. Хотелось бы узнать причину, поскольку она слегка расстраивает.

X = "X" #This is to indicate one piece of the game 
O = "O" #this is to indicate another piece of the game 
EMPTY = "" # an empty square on the board. 
TIE = "TIE" #represents a tie game 
NUM_SQUARES = "9" #number of squares on the board 

def display_instruct(): #this is a function with the name display_instruct. 
    """display game instructions.""" 
    print \ 
      """ Welcome to the greatest challenge of all time: Tic-tac toe. This would be a showdown betweene your human brain 
and my silcon processor You will mkae your move known by entering a number 

        0 | 1 | 2 
        --------- 
        3 | 4 | 5 
        --------- 
        6 | 7 |8 

     Prepare yourself, human. The ultimate battle is about to begin. \n """ 

def ask_yes__no(question): 
    """Ask a yes or no question""" 
    response = None 
    while response not in ("y", "n"): 
     response = raw_input(question).lower() 
    return response 

#this produces a function. It receives a question and thenn responds with an answer which is either yes or not 

def ask_number(question, low, high): 
    """Ask for a number within the range""" 
    response = None 
    while response not in range(low, high): 
     response - int(raw_input(question)) 
    return response 
    #remember that when defining the functions, you have to put in colons. The user recieves a question and then has to give an answer. 

def pieces(): 
    """Determine if player or computer goes first""" #docstrings are used to name the functions. 
    go_first = ask_yes_no("Do you requre the first move?y/n: ") 
    if go_first == "y":      #important to have two equal signs because you are giving a variable a name. Notice that one function callled another. 
     print "\n Then take the first move, you will need it." 
     human = X 
     computer = 0 
    else: 
     print "\n Your bravery will beyour undoing .... I will go first." 
     computer = X 
     human = O 
    return computer, human 
+3

Вы не * работаете * ничего. Вы определили кучу констант и функций, но вы их не называете. Вы хотели назвать функцию? (Кроме того, ваш отступ поврежден.) – user2357112

+0

Я видел этот код раньше ... это игра Tic-Tac-Toe из главы 6 книги _Python Programming для Absolute Beginner_? – iCodez

+0

Эй, ребята, да, это игра Tic Tac Toe. Вы использовали его? – TKA

ответ

2

Вы должны определить и назвать главной функции

def main(): 
    display_instruct() 
    #the rest of the code 


if __name__ == "__main__": 
    main() 

Причина ваш код не работает, потому что то, что у вас есть функция определений

def func() ...

и значение присвоения

x=5

Чтобы на самом деле запустить что-то, вам нужно будет либо определить основную функцию, которая принимает все то, что вы определили, и сочетает их значимым образом, либо добавляет к нижней части кода что-то похожее на то, что вы напишете в главном функция.

+0

Спасибо, Михал. – TKA

Смежные вопросы