| import streamlit as st | |
| from datetime import date | |
| def calculate_age(birth_date): | |
| today = date.today() | |
| age = today.year - birth_date.year - ( | |
| (today.month, today.day) < (birth_date.month, birth_date.day) | |
| ) | |
| return age | |
| def main(): | |
| st.set_page_config(page_title="Age Calculator", page_icon="π") | |
| st.title("π Age Calculator") | |
| st.markdown("Enter your birthdate to calculate your age.") | |
| birth_date = st.date_input("Select your birthdate") | |
| if st.button("Calculate Age"): | |
| age = calculate_age(birth_date) | |
| st.success(f"Your age is: **{age}** years") | |
| if __name__ == "__main__": | |
| main() | |