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
Post a Comment