This repository was archived by the owner on May 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ import time
2+
3+ # judge the leap year
4+ def judge_leap_year (year ):
5+ if (year % 4 ) == 0 :
6+ if (year % 100 ) == 0 :
7+ if (year % 400 ) == 0 :
8+ return True
9+ else :
10+ return False
11+ else :
12+ return True
13+ else :
14+ return False
15+
16+ # returns the number of days in each month
17+ def month_days (month , leap_year ):
18+ if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12 :
19+ return 31
20+ elif month == 4 or month == 6 or month == 9 or month == 11 :
21+ return 30
22+ elif month == 2 and leap_year :
23+ return 29
24+ elif month == 2 and (not leap_year ):
25+ return 28
26+
27+
28+ name = input ("input your name: " )
29+ age = input ("input your age: " )
30+ localtime = time .localtime (time .time ())
31+
32+ year = int (age )
33+ month = year * 12 + localtime .tm_mon
34+ day = 0
35+
36+ begin_year = int (localtime .tm_year ) - year
37+ end_year = begin_year + year
38+
39+ # calculate the days
40+ for y in range (begin_year , end_year ):
41+ if (judge_leap_year (y )):
42+ day = day + 366
43+ else :
44+ day = day + 365
45+
46+ leap_year = judge_leap_year (localtime .tm_year )
47+ for m in range (1 , localtime .tm_mon ):
48+ day = day + month_days (m , leap_year )
49+
50+ day = day + localtime .tm_mday
51+
52+
53+ print ("%s's age is %d years or %d months or %d days" % (name , year , month , day ))
You can’t perform that action at this time.
0 commit comments