I'm having a hard time figuring out how to pass a function's return as a parameter to another function. I've searched a lot of threads that are deviations of this problem but I can't think of a solution from them. My code isn't good yet, but I just need help on the line where the error is occurring to start with.
Instructions:
- create a function that asks the user to enter their birthday and returns a date object. Validate user input as well. This function must NOT take any parameters.
- create another function that takes the date object as a parameter. Calculate the age of the user using their birth year and the current year.
def func1():
bd = input("When is your birthday? ")
try:
dt.datetime.strptime(bd, "%m/%d/%Y")
except ValueError as e:
print("There is a ValueError. Please format as MM/DD/YYY")
except Exception as e:
print(e)
return bd
def func2(bd):
today = dt.datetime.today()
age = today.year - bd.year
return age
This is the Error I get:
TypeError: func2() missing 1 required positional argument: 'bday'
So far, I've tried:
- assigning the func1 to a variable and passing the variable as func2 parameter
- calling func1 inside func2
- defining func1 inside func2
def func2(bd):alone cannot cause that error. That error is caused when the function is called. Show wherefunc2is called. That error means though that you aren't passing the required argument to the function. Also note thatdt.datetime.strptime(bday, "%m/%d/%Y")isn't doing anything infunc1since you never use the results from it.def func2(bday) : #ERROR OCCURS HEREbdaybut the posted code defines the argument name asbd. The code does not match the error. It is much harder to help when you do not post your actual code.