I was wondering if there was a way to store a function in a variable that includes a variable that has not yet been defined, and place that variable that holds the function in after the variable in the function has been defined. For example, I want this script below (this script is an example of the problem I am having in another script, yet the other script is way too long to include here) to print a number of days after you enter in weeks, however I get a NameError: name 'days_weeks' is not defined .
weeks = int(input("Enter a number of weeks"))
def print_weeks():
print("that is %s days" % days_weeks)
x = print_weeks
def find_days():
days_weeks = weeks * 7
x
x()
find_days()
Now, obviously, I can just plug print_weeks in find_days; however for the project I am working on I am using the first function (print_weeks in this case) dozens of times in my script, and the function is hundred of lines of code long, so I want to keep the function stored in a variable to make things way less sloppy. I have also tried to make days_week a global variable, yet the outcome of the code has stayed the same (or I just did it wrong). I have read a lot of other threads yet I have not been able to find an answer. Sorry if this has been confusing, but basically if anyone has a way to keep print_weeks in a variable and have this script print the days correctly it would be greatly appreciated.
x = print_weeksis unnecessary. Just useprint_weekswhere you would usex.