I do not understand why the instructions are being printed off of the margin(about 5 spaces). I would think they would be directly on the margin. I am talking about this part in particular

you first need to choose to go first or second. If you
choose to go first you will be X's. If you choose to
go second you will be O's. you will choose your 'move'
on the board by using the following key.

# print_board.py
#
# this function prints the board, it takes
# its parameter in the form of a list, the 
# list must have at least 9 elments

def print_board(order):
    print ' ',order[0], '|', order[1], '|', order[2]
    print ' -----------'
    print ' ',order[3], '|', order[4], '|', order[5]
    print ' -----------'
    print ' ',order[6], '|', order[7], '|', order[8]

# instructions.py
#
# this function gives instuctions to 
# the user for playing the game





def instructions():


    print """\n\n\tWelcome to the game of tic-tac-toe\n
    \t --a game of man against machine--\n\n
    you first need to choose to go first or second. If you
    choose to go first you will be X's. If you choose to
    go second you will be O's.\n
    you will choose your 'move' on the board by using the 
    following key.\n\n"""

    instruc_list = [ '1','2','3','4','5','6','7','8','9' ]
    
    print_board(instruc_list)
    print ' '

instructions()

Recommended Answers

All 2 Replies

I figured out a way to do it using the triple quotes. Since python expects you to indent properly I assumed my whole function needed to be indented the same. Below is the way I thought it needed to be.

def instructions():


    print """\n\n\tWelcome to the game of tic-tac-toe\n
    \t --a game of man against machine--\n\n
    you first need to choose to go first or second. If you
    choose to go first you will be X's. If you choose to
    go second you will be O's.\n
    you will choose your 'move' on the board by using the 
    following key.\n\n"""

    instruc_list = [ '1','2','3','4','5','6','7','8','9' ]
    
    print_board(instruc_list)
    print ' '

but when using triple quotes, you are allowed to place the part in between triple quotes on the margin, that seems to be an exception to the indention rule. This code works

def instructions():


    print """\n\n\tWelcome to the game of tic-tac-toe\n
\t --a game of man against machine--\n\n
you first need to choose to go first or second. If you
choose to go first you will be X's. If you choose to
go second you will be O's.\n
you will choose you 'move' on the board by using the 
following key.\n\n"""

    instruc_list = [ '1','2','3','4','5','6','7','8','9' ]
    
    print_board(instruc_list)
    print ' '

Whatever is between the triple quotes is one string and not part of the statement indentation rules. I guess you figured that out by trial and error, good way to do it!

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.