I'm learning python, and am having a problem with global variables/lists. I'm writing a basic manual tower of hanoi program, here's the program currently:
pilar1 = [5,4,3,2,1,0]
pilar2 = [0,0,0,0,0,0]
pilar3 = [0,0,0,0,0,0]
def tower_of_hanoi():
global pillar1
global pillar2
global pillar3
print_info()
def print_info():
global pillar1
global pillar2
global pillar3
for i in range(4,-1,-1):
print(pillar1[i], " ", pillar2[i], " ", pillar3[i])
I've tried a few variations, but every time I got the error "NameError: global name 'pillar1' is not defined".
What would be the best way to handle a global list in this setting? I'd prefer to just use one source file, if possible. Thanks!