I am writing a test function to test a section of code before putting it into the file. This is just a sample. I've declared the variable 'map' at the top along with several others. When I run this code it gives me the variable called before definition error.
I can pas 'map' into the function and it works fine but this shouldn't be the case since 'map' is a global variable right? 'dict' works just fine. I thought maybe it was because I was assigning 'map = whatever' in the code but I rewrote it to include 'remap = map + 100' and it still flag 'map' as not being a legitimate variable to call. It's gotta be something simple but I'm not seeing it.
Note: converting 'map' to a string and formatting it with a leading zero is just a personal preference to make other parts of the code more user reader-friendly.
map = 101
dict = {'0302' : 'Hello.', '0202' : 'Hi.', '0201' :'Sup.'}
def test():
while 1 > 0:
choice = input('Add a number.')
if choice == '1':
map = map + 100
map = str(format(map, '04d'))
elif choice == '2':
map = map + 1
map = str(format(map, '04d'))
else:
test()
if map in dict:
print(dict[map])
else:
pass
print(map)
map = int(map)
test()