Skip to content

Commit a05fef8

Browse files
authored
Add files via upload
1 parent 90afd79 commit a05fef8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Import the following modules
2+
from dateutil.relativedelta import relativedelta
3+
from datetime import datetime
4+
from time import strptime
5+
from pywebio.input import *
6+
from pywebio.output import *
7+
from pywebio.session import *
8+
import time
9+
10+
while True: # Run infinite loop
11+
clear() # Clear all the stuffs
12+
# Put a logo of Age Calculator
13+
put_html("<p align=""left""><h4><img src=""https://cdn.icon-icons.com/icons2/562/PNG/512/calculator_icon-icons.com_54044.png"" width=""25px""> AGE CALCULATOR</h4></p>")
14+
date = datetime.now().strftime("%d/%m/%Y") # Getting Current time.
15+
# Taking age from the user
16+
DOB = input("", placeholder="Your Birth Date(dd/mm/yyyy)")
17+
try:
18+
# Check whether the input age format is same as given format
19+
val = strptime(DOB, "%d/%m/%Y")
20+
except:
21+
# If format is different, then through an error.
22+
put_error("Alert! This is not the right format")
23+
time.sleep(3) # sleep for 3 seconds
24+
continue
25+
in_date = DOB.split('/') # Split the age by '/'
26+
date = date.split('/') # split the todays date by '/'
27+
# Typecast all the converted part into the int.
28+
in_date = [int(i) for i in in_date]
29+
date = [int(i) for i in date]
30+
newdate = [] # Define an empty list
31+
in_date[0], in_date[2] = in_date[2], in_date[0] # Swap days with months
32+
date[0], date[2] = date[2], date[0]
33+
if in_date <= date:
34+
now = datetime.strptime(DOB, "%d/%m/%Y")
35+
# Display output
36+
popup("Your Age", [put_html("<h4>"f"{relativedelta(datetime.now(),now).years} Years</br> {relativedelta(datetime.now(),now).months} Months</br>{relativedelta(datetime.now(),now).days} Days""</h4>"), put_buttons(
37+
['Close'], onclick=lambda _: close_popup())], implicit_close=True)
38+
else:
39+
# If you input the year greater than current year
40+
put_warning(
41+
f"No result found, this is {date[0]}, and you can't be in {in_date[0]}.")
42+
time.sleep(3)
43+
clear()
44+
# Give user a choice
45+
choice = radio("Do you want to calculate again?",
46+
options=['Yes', 'No'], required=True)
47+
if choice.lower() == 'yes':
48+
continue
49+
else:
50+
clear()
51+
toast("Thanks a lot!") # Show a toast notification
52+
exit()

0 commit comments

Comments
 (0)