NameError problem
jasonpark (3)

The output says that I have a NameError: name 'month' is not defined. But I'm pretty sure it is returned from the function "get_filters()". What am I doing wrong here? Thanks in advance to all that help.

You are viewing a single comment. View All
leon332157 (69)

@jasonpark https://repl.it/@leon332157/ObedientBasicMicrobsd

Use it with out a main function and add a global keyword will make the variable global accessible.

jasonpark (3)

@leon332157 how do i make the variable global when it is produced in a function from a user input? also, when the function returns a variable, does that not make it global?

jasonpark (3)

@leon332157 I would take out the main function but I need the program to be able to restart under the while loop in the main function.

leon332157 (69)

@jasonpark So split the question into two parts, first, if you want to make a variable from a function global, you can use the global keyword at the start of the function, like
def fun():
.global name
.name=input('name')

and the second part is, the value functions returns can be the same name as your variable outside of the function, but returning the variable inside of the function will not change the variable outside of the function unless the variable is a global variable, when a variable is global, you can change it in the function, no need for return.

jasonpark (3)

@leon332157 I see! Thank you very much!