Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from datetime import date
|
3 |
+
|
4 |
+
def calculate_age(birth_date):
|
5 |
+
today = date.today()
|
6 |
+
age = today.year - birth_date.year - (
|
7 |
+
(today.month, today.day) < (birth_date.month, birth_date.day)
|
8 |
+
)
|
9 |
+
return age
|
10 |
+
|
11 |
+
def main():
|
12 |
+
st.set_page_config(page_title="Age Calculator", page_icon="π")
|
13 |
+
st.title("π Age Calculator")
|
14 |
+
st.markdown("Enter your birthdate to calculate your age.")
|
15 |
+
|
16 |
+
birth_date = st.date_input("Select your birthdate")
|
17 |
+
|
18 |
+
if st.button("Calculate Age"):
|
19 |
+
age = calculate_age(birth_date)
|
20 |
+
st.success(f"Your age is: **{age}** years")
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
main()
|