Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import streamlit as st
|
3 |
+
from datetime import date, datetime
|
4 |
+
|
5 |
+
# Page settings
|
6 |
+
st.set_page_config(page_title="Age Calculator", page_icon="π", layout="centered")
|
7 |
+
|
8 |
+
# Title
|
9 |
+
st.title("π Age Calculator")
|
10 |
+
st.markdown("Enter your birthdate below to calculate your current age.")
|
11 |
+
|
12 |
+
# Input
|
13 |
+
birth_date = st.date_input("π
Select your birthdate", min_value=date(1900, 1, 1), max_value=date.today())
|
14 |
+
|
15 |
+
# Button
|
16 |
+
if st.button("Calculate Age"):
|
17 |
+
today = date.today()
|
18 |
+
|
19 |
+
# Age in years
|
20 |
+
age_years = today.year - birth_date.year - (
|
21 |
+
(today.month, today.day) < (birth_date.month, birth_date.day)
|
22 |
+
)
|
23 |
+
|
24 |
+
# Age in months and days
|
25 |
+
delta = today - birth_date
|
26 |
+
age_days = delta.days
|
27 |
+
age_months = age_days // 30
|
28 |
+
|
29 |
+
# Output
|
30 |
+
st.success(f"π You are **{age_years} years** old.")
|
31 |
+
st.info(f"π That's approximately **{age_months} months** or **{age_days} days** old.")
|
32 |
+
|
33 |
+
# Birthday message
|
34 |
+
if today.month == birth_date.month and today.day == birth_date.day:
|
35 |
+
st.balloons()
|
36 |
+
st.markdown("π **Happy Birthday!** ππ")
|
37 |
+
|
38 |
+
# Footer
|
39 |
+
st.markdown("---")
|
40 |
+
st.markdown("Made with β€οΈ using Streamlit")
|