Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

age calculator python

import datetime
def Age_Calculator():
    '''create a python function that takes user birth year & month & day and prints
how old he is
args:name,birthday,birthmonth,birthyear
return : current age in years&monthand days
'''
    name = input("please enter your name :".title())
    today = datetime.date.today()
    birthday, birthmonth, birthyear = int(input("enter your bithday : ".title())), int(
        input("enter your bithmonth : ".title())), int(input("enter your bithyear : ".title()))
    # input birth year& month and day
    my_age_year, my_age_month, my_age_day = abs(
        today.year-birthyear), abs(today.month-birthmonth), abs(today.day-birthday)
    # get current age from today-my_birthdate
    nex_birthdate = datetime.date(today.year+1, birthmonth, birthday)
    #birth date in next year
    num_day = nex_birthdate-today
    print(
        f"congratulations {name} your age is {my_age_year} years & {my_age_month} month and {my_age_day} days".title())
    print(
        f"congratulations {name} your next birthdate after {num_day.days} days ".title())
Age_Calculator()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #age #calculator #python
ADD COMMENT
Topic
Name
8+8 =