Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (11.4k points)

This example is from Project Euler's problem number 11. The one with the grid.

I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and I'm not sure why

grid = [
[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ],
[ 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00 ],
[ 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65 ],
...


And I get this error:

  File "D:\development\Python\ProjectEuler\p11.py", line 3
    [ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91 , 08 ],
       ^ SyntaxError: invalid token

 

Can anyone help me with this? Why is it throwing an error before the comma?

1 Answer

0 votes
by (32.3k points)

When you are starting a literal number with a 0, it interprets it as an octal number and you can't have an '8' in an octal number. Just try to fix that according to your case.

Browse Categories

...