KZTech commited on
Commit
9bfd450
Β·
verified Β·
1 Parent(s): 2b52c2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,18 +1,19 @@
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
@@ -27,8 +28,8 @@ with col3:
27
  # Logic
28
  if calculate:
29
  today = date.today()
30
- age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
31
- st.success(f"πŸŽ‰ You are {age_years} years old!")
32
 
33
  if clear:
34
  st.experimental_rerun()
 
1
  import streamlit as st
2
  from datetime import date
3
+ from dateutil.relativedelta import relativedelta
4
 
5
  # Configure the page
6
  st.set_page_config(page_title="Age Calculator", layout="centered")
7
 
8
  # Title and intro
9
  st.title("πŸŽ‚ Age Calculator")
10
+ st.subheader("Find your exact age in Years, Months, and Days")
11
 
12
+ # Min and max date
13
  min_dob = date(1950, 1, 1)
14
  max_dob = date.today()
15
 
16
+ # Date input with limits
17
  dob = st.date_input("πŸ“… Select your Date of Birth", min_value=min_dob, max_value=max_dob, value=date(2000, 1, 1))
18
 
19
  # Buttons
 
28
  # Logic
29
  if calculate:
30
  today = date.today()
31
+ diff = relativedelta(today, dob)
32
+ st.success(f"πŸŽ‰ You are {diff.years} years, {diff.months} months, and {diff.days} days old!")
33
 
34
  if clear:
35
  st.experimental_rerun()