-
Notifications
You must be signed in to change notification settings - Fork 1
/
age-calculator.py
69 lines (69 loc) · 2.07 KB
/
age-calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
##hello terance##
from datetime import datetime
now = datetime.now()
ty = now.year
tm = now.month
td = now.day
ans = "y"
while ans == 'y' or ans == 'Y':
dob = raw_input("Enter your date of birth in dd/mm/yyyy format:")
l = dob.split("/")
bd = int(l[0])
bm = int(l[1])
by = int(l[2])
if bm != 2 or bd != 29:
if tm == 1 or tm == 2 or tm == 4 or tm == 6 or tm == 8 or tm == 9 or tm == 11:
d = 31
elif tm == 3:
if ty % 4 == 0 and (ty % 100 != 0 and ty % 400 == 0):
d = 29
else:
d = 28
else:
d = 30
if by <= ty:
def date():
if td > bd:
ad = td-bd
elif td == bd:
ad = 0
else:
n = bd-td
ad = d-n
return ad
if tm > bm:
if td > bd:
am = tm-bm
else:
am = tm-bm-1
ay = ty-by
date()
elif tm == bm:
date()
if date() == 0:
print "Happy Birthday"
am = 0
ay = ty-by
else:
if bd < td:
am = 0
ay = ty-by
else:
am = 11
ay = ty-by-1
else:
date()
ch = bm-tm
if bd < td:
am = 12-ch
ay = ty-by
else:
am = 11-ch
ay = ty-by-1
print "\nYou are", ay, "years", am, "months and", date(), "days old."
else:
print "Invalid Birth year"
else:
print "So you are a leap year baby na,Sorry I can't calculate your age,may be 1/4th of your present age, hahahaha!"
ans = raw_input("\nDo you wish to continue(y/n)?\n ->>")
print "...................................................\n\n"