Answers for "find age using python"

7

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))
Posted by: Guest on April-17-2021
0

age check python

#  Imports
import datetime
import time
while True:
    #  Variables & Big Catching
    age = input('What year where you born? ')
    current_time = datetime.datetime.now().year
    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() and len(age) == 4:
        int_age = int(age)
    if int_age < 1900:
        print('Please enter a valid year!')
        quit()
    elif int_age > current_time:
        print('Please enter a valid year!')
        quit()
    final_age = current_time - int_age
    print('You are', final_age, 'or', final_age - 1, 'years old')

    time.sleep(1)
Posted by: Guest on March-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language