-2

This is some of my basic python code:

width = 8
length = 8
board = [[0 for col in range(length)] for row in range(width)]
print(board)

This prints correctly on PyCharm as an 8x8 grid filled with zeros.

But when I run this it doesn't work:

def main():
    width = 8  # letters, col
    length = 8  # nums, row
    board = [[0 for col in range(length)] for row in range(width)]
    print(board)

All I get is "Process finished with exit code 0" and nothing is printed. I checked the same on LeetCode Playground and ran into the same issue.

Any tips on why this might be happening?

Thank you!

buran
  • 13,682
  • 10
  • 36
  • 61
aryan
  • 1
  • 1

1 Answers1

0

That is because you're not explicitly calling the function anywhere else in your code.

you have to call the function like main() right after your method for you to see the results, otherwise Python wouldn't know. It'll only compile your code but not execute.

def main():
    width = 8  # letters, col
    length = 8  # nums, row
    board = [[0 for col in range(length)] for row in range(width)]
    print(board)

main()
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • @aryan if you found it helpful please upvote or mark it as answer so that it'll help someone down the line – Kulasangar Dec 29 '22 at 09:00
  • I can't upvote yet because I don't have 15 reputation. I only just got my account, but when I do I'll definitely upvote! – aryan Dec 29 '22 at 09:08