Forum Archive

Getting started

dougler1

I’m new to python and use IDLE on my laptop.
I copied some code into what appears to be the editing area - where the examples appear.
I gave it a name that appears on the upper tabs, but I can’t run the program. The run icon above dose nothing and I can’t find documentation on the mechanics of the editor.

stephen

ensure your script file has .py extention if run is grayed out. Also what is expected when you run the script?

dougler1

The script is called gameBoard.py which is in gray text in the tabs. The run arrowhead is in gray. From the examples I think it should be in green to be active.
The file itself is just a series of print statements about 10 lines long. I just want to get a feel for the editor

mikael

@dougler1, my ”run triangle” or ”play button” is just empty (white) with a blue outline. Could be different with a different theme, though.

I assume nothing happens when you press it? Or could it very briefly turn into a box with an x in it?

Maybe paste your code in here just to be sure?

7upser

@dougler1, or send a screenshot, so we know where you are within your Pythonista.

To send a screenshot you can use:
![tag](url)
-and-
https://imgur.com/

stephen

@dougler1

as @mikael said, if you could present the code it would help alot.if itsbonly 10 or so lines then you could be executing the code but not telling it to show anything. thisvwould make it seem like its doing nothing when in fact it just ran the program really fast

dougler1

Here Is the code I’m trying to run

board=['1','2','3', '4','5', '6', '7','8','9']
def play():
    print('got here')
    printBoard
def printBoard(): 
    print
    for square in range (0,9 ):
        print('|', board [square],'|', end='')

        if square ==2 or square ==5 :
            print ('\n')
            print('__________')
            print

if __name__==' __main__':
        play()
dougler1

Error was between seat and keyboard...thanks

stephen

Just a seggestion 😊 ... or two if board is going to be a list of numeric strings in order you can also just use range to create your board squars without the list object. that way you dont create two sparate lists each time (board and range). and fstring to help control spacing more. while we are t it lets throw in a new line variable 😁

For Example:

for square in range(1, 10): # 1-9
    nl = '\n' if square%3 == 0 else ''
    print(f'| {square} |{nl}', end='')

prints:

| 1 || 2 || 3 |
| 4 || 5 || 6 |
| 7 || 8 || 9 |

As for myself, I like to use Unicode in my console apps
I'll show an example of how I would implement a Board 😊

using the same 3x3 setup:

top = "╔═╦═╦═╦═╦═╦═╗\n"
between = "╠═╬═╬═╬═╬═╬═╣\n"
bottom = "╚═╩═╩═╩═╩═╩═╝\n"
board = top
rows = 3
for n in range(rows):
    board += f'╠ {n*3+1} ╬ {n*3+2} ╬ {n*3+3} ╣\n'
    if n+1 != rows:
        board += between
    else:
        board += bottom

print(board)

prints:

╔═╦═╦═╦═╦═╦═╗
╠ 1 ╬ 2 ╬ 3 ╣
╠═╬═╬═╬═╬═╬═╣
╠ 4 ╬ 5 ╬ 6 ╣
╠═╬═╬═╬═╬═╬═╣
╠ 7 ╬ 8 ╬ 9 ╣
╚═╩═╩═╩═╩═╩═╝

many ways to do it. just figured id share 😇