youtube-code/2022-10-10-6-Coding-Concepts-You-MUST-Know-For-Beginners/variables.py
2022-11-05 14:07:34 +00:00

11 lines
No EOL
298 B
Python

import datetime
def calculate_age(dateOfBirth):
today = datetime.datetime.now()
age = today.year - dateOfBirth.year - ((today.month, today.day) < (dateOfBirth.month, dateOfBirth.day))
return age
dateOfBirth = datetime.datetime(1990, 9, 20)
age = calculate_age(dateOfBirth)
print(age)