KZTech commited on
Commit
2b52c2c
Β·
verified Β·
1 Parent(s): 94ff0e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,14 +1,30 @@
1
  import streamlit as st
2
  from datetime import date
3
 
 
4
  st.set_page_config(page_title="Age Calculator", layout="centered")
 
 
5
  st.title("πŸŽ‚ Age Calculator")
6
- st.subheader("Calculate your age from your date of birth")
 
 
 
 
 
 
 
7
 
8
- dob = st.date_input("πŸ“… Select your Date of Birth", value=date(2000, 1, 1))
9
- calculate = st.button("πŸ”’ Calculate Age")
10
- clear = st.button("πŸ—‘οΈ Clear")
 
 
 
 
 
11
 
 
12
  if calculate:
13
  today = date.today()
14
  age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
@@ -16,3 +32,11 @@ if calculate:
16
 
17
  if clear:
18
  st.experimental_rerun()
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from datetime import date
3
 
4
+ # Configure the page
5
  st.set_page_config(page_title="Age Calculator", layout="centered")
6
+
7
+ # Title and intro
8
  st.title("πŸŽ‚ Age Calculator")
9
+ st.subheader("Calculate your age from your date of birth (starting from 1950)")
10
+
11
+ # Set min and max date
12
+ min_dob = date(1950, 1, 1)
13
+ max_dob = date.today()
14
+
15
+ # Date input with restriction
16
+ dob = st.date_input("πŸ“… Select your Date of Birth", min_value=min_dob, max_value=max_dob, value=date(2000, 1, 1))
17
 
18
+ # Buttons
19
+ col1, col2, col3 = st.columns(3)
20
+ with col1:
21
+ calculate = st.button("πŸ”’ Calculate Age")
22
+ with col2:
23
+ clear = st.button("πŸ—‘οΈ Clear")
24
+ with col3:
25
+ exit_btn = st.button("❌ Exit")
26
 
27
+ # Logic
28
  if calculate:
29
  today = date.today()
30
  age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
 
32
 
33
  if clear:
34
  st.experimental_rerun()
35
+
36
+ if exit_btn:
37
+ st.warning("App exited.")
38
+ st.stop()
39
+
40
+ # Footer
41
+ st.markdown("---")
42
+ st.caption("Built with ❀️ using Streamlit")