Spaces:
Sleeping
Sleeping
File size: 1,073 Bytes
a25fc13 9bfd450 a25fc13 2b52c2c a25fc13 2b52c2c a25fc13 9bfd450 2b52c2c 9bfd450 2b52c2c 9bfd450 2b52c2c a25fc13 2b52c2c a25fc13 2b52c2c a25fc13 9bfd450 a25fc13 2b52c2c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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")
|