shanenin Posted June 23, 2005 Report Share Posted June 23, 2005 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 particularyou first need to choose to go first or second. If youchoose to go first you will be X's. If you choose togo second you will be O's. you will choose your 'move'on the board by using the following key.if you run the script you will see what I mean. below is the script# 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 elmentsdef 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 gamedef 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()here is the output if you do not want to run it Welcome to the game of tic-tac-toe --a game of man against machine-- 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. 1 | 2 | 3 ----------- 4 | 5 | 6 ----------- 7 | 8 | 9 Quote Link to post Share on other sites
iccaros Posted June 23, 2005 Report Share Posted June 23, 2005 try this I removed your end of lines (EOL)which removed the need for triple quotes which I think was changing your format of out put by putting in 3 spaces (one for each quote). Hint if you are typing into one print statment do not hit enter. def instructions(): print "\n\n\tWelcome to the game of tic-tac-toe\n\t--a game of man against machine--\n\nyou first need to choose to go first or second.\nIf you choose to go first you will be X's.\nIf you choose to go second you will be O's.\nyou will choose your 'move' on the board by using the following key.`\n\n`"here is my outputsteves-power-mac-g4:~ whuskey$ python test.py Welcome to the game of tic-tac-toe --a game of man against machine--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.`` 1 | 2 | 3 ----------- 4 | 5 | 6 ----------- 7 | 8 | 9 Quote Link to post Share on other sites
shanenin Posted June 23, 2005 Author Report Share Posted June 23, 2005 (edited) 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 worksdef instructions(): print """\n\n\tWelcome to the game of tic-tac-toe\n\t --a game of man against machine--\n\nyou first need to choose to go first or second. If youchoose to go first you will be X's. If you choose togo second you will be O's.\nyou 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 ' ' Edited June 23, 2005 by shanenin Quote Link to post Share on other sites
jcl Posted June 23, 2005 Report Share Posted June 23, 2005 The aesthetics of multiline strings always suck.By the way, you can toss all of the explicit newlines and tabs if you want.def instructions(): print """ Welcome to the game of tic-tac-toe --a game of man against machine--you first need to choose to go first or second. If youchoose to go first you will be X's. If you choose togo second you will be O's.you will choose your 'move' on the board by using the following key.""" instruc_list = [ '1','2','3','4','5','6','7','8','9' ] print_board(instruc_list) print ' '(This board eats tabs characters, but they do work.) Quote Link to post Share on other sites
shanenin Posted June 23, 2005 Author Report Share Posted June 23, 2005 (This board eats tabs characters, but they do work.)<{POST_SNAPBACK}>phpbb totally screws up my indenting. It makes my python code unrunable, assuming you just cut and pasted the results. Quote Link to post Share on other sites
jcl Posted June 24, 2005 Report Share Posted June 24, 2005 (edited) phpbb totally screws up my indenting. It makes my python code unrunable, assuming you just cut and pasted the results.<{POST_SNAPBACK}>Indeed. The board does brute-force formatting with non-breaking spaces and line breaks instead of using the pre element or CSS, and sets a proportional font in code blocks. Really makes a mess of things. Sadly the WWW is slightly hostile to source code; it takes a rediculous amount of effort to make everything work all the time.On the bright side, XHTML2 looks like it will greatly improve the situation with the new blockcode (source code block, all formatting preserved), code (inline source code), var (variable name), l (line), kbd (sample user input), and samp (sample program output) elements. It's even been suggesed that pages could specify the source language (possibly with the xml:lang attribute, though that might be abusive) so browsers could apply syntax highlighting.Tabs will probably never work though.Getting back to Python, I don't know if you've come across it yet, but Python includes a neat little feature called 'docstrings' (lifted from Common Lisp, probably). The first statement in a function definition can be a string, which becomes the documentation for that function. If you replace the comments in your original code with docstringsdef instructions():   "this function gives instuctions to the user for playing the game"   print """   Welcome to the game of tic-tac-toe --a game of man against machine--you first need to choose to go first or second. If youchoose to go first you will be X's. If you choose togo second you will be O's.you will choose your 'move' on the board by using the following key."""   instruc_list = [ '1','2','3','4','5','6','7','8','9' ]    print_board(instruc_list)   print ' 'then you load it in the interpreter (using whatever filename you use, here 'p') and ask for help on the function$ pythonPython 2.3.5 (#1, May  5 2005, 17:00:26) [GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import p>>> help(p.instructions)it will print a nice summaryHelp on function instructions in module p:instructions()   this function gives instuctions to the user for playing the game Edited June 24, 2005 by jcl Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.