Abdullah-Basar commited on
Commit
f9d6ed6
Β·
verified Β·
1 Parent(s): 49718e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datetime import datetime, timedelta
3
+
4
+ # App Title and Description
5
+ st.title("πŸŽ‚ Age Calculator")
6
+ st.write("""
7
+ Calculate your age in years, minutes, and seconds!
8
+ See your next 5 birthdays and get a detailed textual output in English.
9
+ """)
10
+
11
+ # Input: Date of Birth
12
+ dob = st.date_input("Enter your Date of Birth (YYYY-MM-DD):")
13
+
14
+ # Calculate Age
15
+ if dob:
16
+ today = datetime.now()
17
+ dob_datetime = datetime.combine(dob, datetime.min.time())
18
+
19
+ age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
20
+ age_days = (today - dob_datetime).days
21
+ age_minutes = age_days * 24 * 60
22
+ age_seconds = age_minutes * 60
23
+
24
+ # Display Age
25
+ st.subheader("πŸ•’ Your Age:")
26
+ st.write(f"**Years:** {age_years}")
27
+ st.write(f"**Minutes:** {age_minutes:,}")
28
+ st.write(f"**Seconds:** {age_seconds:,}")
29
+
30
+ # Next 5 Birthdays
31
+ st.subheader("πŸŽ‰ Next 5 Birthdays:")
32
+ next_birthdays = []
33
+ next_birthday = datetime(today.year, dob.month, dob.day)
34
+ if next_birthday < today:
35
+ next_birthday = datetime(today.year + 1, dob.month, dob.day)
36
+
37
+ for _ in range(5):
38
+ next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
39
+ next_birthday += timedelta(days=365 + (1 if (next_birthday.year % 4 == 0 and (next_birthday.year % 100 != 0 or next_birthday.year % 400 == 0)) else 0))
40
+
41
+ for idx, birthday in enumerate(next_birthdays, start=1):
42
+ st.write(f"{idx}. {birthday}")
43
+
44
+ # English Textual Output
45
+ st.subheader("πŸ“œ Age in English:")
46
+ st.write(f"You are **{age_years} years old**, which is approximately **{age_minutes:,} minutes** or **{age_seconds:,} seconds**.")
47
+ st.write("Your next five birthdays will be on the dates listed above.")
48
+
49
+ # Footer
50
+ st.write("---")
51
+ st.markdown("πŸ’‘ **Developed by Abdullah**")