learning python learning python - 3 months ago 10
Python Question

Type Error Occured in python executed in visual studio

i am running the below code to calculate current age in python using visual studio.

but i am getting the below piece of error:
Error:

Type Error Occured
Unsupported operand Type for built_in_function or method


code:

import datetime

def my_current_age():
user_input = input("enter year")
date_of_birth = (datetime.date(1990 , 10 , 28))
today_date=(datetime.date.today)
current_age = (today_date - date_of_birth)
print("you lived for {}" .format(current_age))


print(my_current_age())


any suggestion python developer please

Thanks

Jim Jim
Answer

You are assigning a method of datetime to today_date with:

today_date=(datetime.date.today)

i.e, you are calling the function. Call it, instead:

today_date=(datetime.date.today())

in order for it to work.

Apart from that, take note that the parenthesis around your expressions are redundant, that is:

today_date=(datetime.date.today())

is directly equivalent to:

today_date = datetime.date.today()