I wrote some code for a Python homework assignment and it's running fine in Mu-editor and other IDE's, but not in the Atom editor (using the Hydrogen package to run it), where it gives me an unexpected NameError. I've already posted this issue in the Atom Github, but I'm not getting a response. The code:
theBoard = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
def printBoard(board):
print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
print('-+-+-')
print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
print('-+-+-')
print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
turn = 'X'
for i in range(9):
printBoard(theBoard)
print('Turn for ' + turn + '. Move on which space?')
move = input()
theBoard[move] = turn
if turn == 'X':
turn = 'O'
else:
turn = 'X'
printBoard(theBoard)
The NameError I get when trying to run this code:
----> 1 printBoard(theBoard)
NameError: name 'theBoard' is not defined
It throws this error in line 1 of the for loop printBoard(theBoard)
I've played around with formatting and shortening theBoard in case the formatting of the dictionary was the problem, but that did not change anything. theBoard is stored in the global scope (right?), so printBoard should be able to call it in the for loop.
Does anybody have an idea why this is happening?