an age calculation app using python

 an age calculation app



python source code


import datetime

def calculate_age(birth_year):
    current_year = datetime.datetime.now().year
    age = current_year - birth_year
    return age

def process_input(user_input):
    try:
        birth_year = int(user_input)
        age = calculate_age(birth_year)
        response = f"You are approximately {age} years old."
    except ValueError:
        response = "Invalid input. Please enter a valid birth year."

    return response

print("Welcome to the Age Calculation App!")

while True:
    user_input = input("Enter your birth year (or 'exit' to quit): ")
   
    if user_input.lower() == "exit":
        break

    response = process_input(user_input)
    print(response)

print("Thank you for using the Age Calculation App!")

 

Comments

Popular posts from this blog

Trading Live Advance Chart Source code HTML CSS & JS

How to show live Cryptocurrency Price In your website Using HTML CSS, AND JavaScript

Learn Python 2024 by gaurav tripathi