Skip to content

Commit 06728df

Browse files
committed
Adding 10th Project
1 parent 3103f78 commit 06728df

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Binary file not shown.
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from pywebio import start_server
2+
from pywebio.input import *
3+
from pywebio.output import *
4+
import datetime
5+
import time
6+
7+
def user_birth():
8+
c_time = datetime.datetime.now()
9+
c_year = c_time.year
10+
11+
input_check = True
12+
while(input_check):
13+
date_of_birth_str = input('Enter your Date of Birth', type=DATE)
14+
date_of_birth = datetime.datetime.strptime(date_of_birth_str, "%Y-%m-%d").date()
15+
if(date_of_birth.year > c_year):
16+
popup('Invalid Date of Birth', 'Please enter a valid Date of Birth before the current year.')
17+
else:
18+
input_check = False
19+
return date_of_birth
20+
21+
def current_date():
22+
return datetime.datetime.now().date()
23+
24+
def calculate_age(birth, date_now):
25+
age_years = date_now.year - birth.year
26+
age_months = date_now.month - birth.month
27+
age_days = date_now.day - birth.day
28+
29+
if age_days < 0:
30+
age_months -= 1
31+
age_days += (date_now - datetime.timedelta(days=date_now.day)).day
32+
33+
if age_months < 0:
34+
age_years -= 1
35+
age_months += 12
36+
37+
total_days = (date_now - birth).days
38+
total_hours = total_days * 24
39+
total_minutes = total_hours * 60
40+
total_seconds = total_minutes * 60
41+
42+
return {
43+
'years': age_years,
44+
'months': age_months,
45+
'days': age_days,
46+
'total_days': total_days,
47+
'total_hours': total_hours,
48+
'total_minutes': total_minutes,
49+
'total_seconds': total_seconds
50+
}
51+
52+
def info_table(d_o_birth, c_date, age):
53+
54+
put_progressbar('bar', auto_close=True)
55+
for i in range(1, 11):
56+
set_progressbar('bar', i / 10)
57+
time.sleep(0.5)
58+
59+
put_table(
60+
[
61+
['Date Of Birth', 'Current Date', 'Total Age', 'Total Days', 'Total Months', 'Total Hours', 'Total Minutes', 'Total Seconds'],
62+
[
63+
f'{d_o_birth}', f'{c_date}', f'{age["years"]} years, {age["months"]} months, {age["days"]} days', f'{age["total_days"]}', f'{age["years"] * 12 + age["months"]}', f'{age["total_hours"]} hr', f'{age["total_minutes"]} min', f'{age["total_seconds"]} sec'
64+
]
65+
]
66+
)
67+
68+
put_image("https://img.freepik.com/free-vector/person-different-ages_23-2148392903.jpg?w=1380&t=st=1719664200~exp=1719664800~hmac=4dfd945bc7289410e4547d325baeaae89fc93cb58c77efbdddaa4df669a00d13")
69+
70+
def main():
71+
put_html("<h1 align='center'>WELCOME TO LIFE SPAN CALCULATOR</h1>")
72+
d_o_birth = user_birth()
73+
c_date = current_date()
74+
age = calculate_age(d_o_birth, c_date)
75+
info_table(d_o_birth, c_date, age)
76+
77+
if __name__ == '__main__':
78+
start_server(main, port=8080, auto_open_webbrowser=True)

0 commit comments

Comments
 (0)