I have func1
that contains a variable, and I want to access that variable in func2
. I have tried in the code below to return the variable in func1
and then set variable "user_name"
to the function "first_name_information"
, but this makes func1
run two times, which I don't want to happen.
def func1():
user_name = input("What's your name? ")
if any(char.isdigit() for char in user_name):
print("You can't put a number in your name.")
sys.exit()
else:
pass
return user_name
def func2():
user_name = first_name_information()
last_name = input("What's your last name {}? ".format(user_name))
if any(char.isdigit() for char in last_name):
print("You can't put a number in your last name.")
sys.exit()
else:
pass