Naz786 commited on
Commit
a8a63ef
Β·
verified Β·
1 Parent(s): 7bc9792

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
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")