Spaces:
Sleeping
Sleeping
# app.py | |
import streamlit as st | |
from datetime import date, datetime | |
# Page settings | |
st.set_page_config(page_title="Age Calculator", page_icon="π", layout="centered") | |
# Title | |
st.title("π Age Calculator") | |
st.markdown("Enter your birthdate below to calculate your current age.") | |
# Input | |
birth_date = st.date_input("π Select your birthdate", min_value=date(1900, 1, 1), max_value=date.today()) | |
# Button | |
if st.button("Calculate Age"): | |
today = date.today() | |
# Age in years | |
age_years = today.year - birth_date.year - ( | |
(today.month, today.day) < (birth_date.month, birth_date.day) | |
) | |
# Age in months and days | |
delta = today - birth_date | |
age_days = delta.days | |
age_months = age_days // 30 | |
# Output | |
st.success(f"π You are **{age_years} years** old.") | |
st.info(f"π That's approximately **{age_months} months** or **{age_days} days** old.") | |
# Birthday message | |
if today.month == birth_date.month and today.day == birth_date.day: | |
st.balloons() | |
st.markdown("π **Happy Birthday!** ππ") | |
# Footer | |
st.markdown("---") | |
st.markdown("Made with β€οΈ using Streamlit") | |