0

I used Python long time ago and decided to revisit it. Downloaded the latest version (3.3.2) and tried to execute a few codes. First thing I learned is that print is now a function. Having in mind this is a fully operational code I can't figure out why it doesn't work now.

Table= [[ 0 for i in range(9)] for j in range(9) ]
for x in range(9):
    for y in range(9):
        if x==0 or x==8 or y==0 or y==8 or (x==4 and y==3) or (x==4 and y==4) or (x==4 and y==5):
            Table[x][y]=1;
for y in range(9):
    for x in range(9):
        print Table[x][y],
    print

When I go "Run Module" a SyntaxError window pops up. The marked phrase being the error is the Table[x][y] in the 2nd row from the bottom. I'm pretty sure this worked last time I tried it. Thanks!

Martin V
  • 55
  • 1
  • 2
  • 6
  • 7
    As you said, print is a function. Do `print(Table[x][y])`. Also get rid of the comma at the end of that line. You also don't need semicolons – YXD Oct 16 '13 at 21:48
  • 1
    @MrE: No, `print(Table[x][y], end=' ')`. The comma is there to prevent a newline being printed. In a print statement, a comma has *meaning*. – Martijn Pieters Oct 16 '13 at 21:49

1 Answers1

1

Putting your code into a file too.py, I ran the 2to3 utility to convert it to Python3 code:

  → 2to3 too.py
  RefactoringTool: Skipping implicit fixer: buffer
  RefactoringTool: Skipping implicit fixer: idioms
  RefactoringTool: Skipping implicit fixer: set_literal
  RefactoringTool: Skipping implicit fixer: ws_comma
  RefactoringTool: Refactored too.py
  --- too.py  (original)
  +++ too.py  (refactored)
  @@ -5,5 +5,5 @@
               Table[x][y]=1;
   for y in range(9):
       for x in range(9):
  -        print Table[x][y],
  -    print
  +        print(Table[x][y], end=' ')
  +    print()
  RefactoringTool: Files that need to be modified:
  RefactoringTool: too.py
tlehman
  • 5,125
  • 2
  • 33
  • 51
  • It works now! Thanks a bunch! I just have one more question: When it reaches a command line that goes: `L= raw_input('Insert number:')` What appears in the Shell is: Traceback (most recent call last): **File "C:\Users\Martin\Desktop\Fakultet\Fakultet (od site semestri)\5ti semestar\OMI domasna python 1\Domasna Python 1\Gotovi za koristenje\domasna proba full.py", line 7, in L= raw_input('Insert number:') NameError: name 'raw_input' is not defined** Any thoughts? – Martin V Oct 16 '13 at 22:04
  • The error says it all, `raw_input` is not defined in python3, use `input` – tlehman Oct 16 '13 at 22:08