python birthdate check age code example
Example 1: python calculate age from date of birth
from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
Example 2: age check python
import datetime
age = input('What year where you born? ')
if age.isdigit() is False:
print('Please enter a number')
quit()
elif len(age) != 4:
print('Please enter a valid year!')
quit()
elif age.isdigit() is True and len(age) == 4:
int_age = int(age)
current_time = datetime.datetime.now().year
print('You are', current_time - int_age, 'Years old')