KZTech's picture
Update app.py
9bfd450 verified
import streamlit as st
from datetime import date
from dateutil.relativedelta import relativedelta
# Configure the page
st.set_page_config(page_title="Age Calculator", layout="centered")
# Title and intro
st.title("πŸŽ‚ Age Calculator")
st.subheader("Find your exact age in Years, Months, and Days")
# Min and max date
min_dob = date(1950, 1, 1)
max_dob = date.today()
# Date input with limits
dob = st.date_input("πŸ“… Select your Date of Birth", min_value=min_dob, max_value=max_dob, value=date(2000, 1, 1))
# Buttons
col1, col2, col3 = st.columns(3)
with col1:
calculate = st.button("πŸ”’ Calculate Age")
with col2:
clear = st.button("πŸ—‘οΈ Clear")
with col3:
exit_btn = st.button("❌ Exit")
# Logic
if calculate:
today = date.today()
diff = relativedelta(today, dob)
st.success(f"πŸŽ‰ You are {diff.years} years, {diff.months} months, and {diff.days} days old!")
if clear:
st.experimental_rerun()
if exit_btn:
st.warning("App exited.")
st.stop()
# Footer
st.markdown("---")
st.caption("Built with ❀️ using Streamlit")