File size: 1,155 Bytes
a8a63ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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")