Skip to content

Commit 7a94dc7

Browse files
authored
Merge pull request #418 from devtayade/master
Added age calculator script- issue solved #417
2 parents 153f741 + dc5e7b1 commit 7a94dc7

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
138138
<sub><b>Khushi Jha</b></sub>
139139
</a>
140140
</td>
141+
<td align="center">
142+
<a href="https://github.com/Khushi260">
143+
<img src="https://avatars.githubusercontent.com/u/94845508?v=4" width="100;" alt="Khushi260"/>
144+
<br />
145+
<sub><b>Khushi Jha</b></sub>
146+
</a>
147+
</td></tr>
148+
<tr>
141149
<td align="center">
142150
<a href="https://github.com/yunghog">
143151
<img src="https://avatars.githubusercontent.com/u/41548444?v=4" width="100;" alt="yunghog"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import time
2+
from calendar import isleap
3+
4+
# judge the leap year
5+
def judge_leap_year(year):
6+
if isleap(year):
7+
return True
8+
else:
9+
return False
10+
11+
12+
# returns the number of days in each month
13+
def month_days(month, leap_year):
14+
if month in [1, 3, 5, 7, 8, 10, 12]:
15+
return 31
16+
elif month in [4, 6, 9, 11]:
17+
return 30
18+
elif month == 2 and leap_year:
19+
return 29
20+
elif month == 2 and (not leap_year):
21+
return 28
22+
23+
24+
name = input("input your name: ")
25+
age = input("input your age: ")
26+
localtime = time.localtime(time.time())
27+
28+
year = int(age)
29+
month = year * 12 + localtime.tm_mon
30+
day = 0
31+
32+
begin_year = int(localtime.tm_year) - year
33+
end_year = begin_year + year
34+
35+
# calculate the days
36+
for y in range(begin_year, end_year):
37+
if (judge_leap_year(y)):
38+
day = day + 366
39+
else:
40+
day = day + 365
41+
42+
leap_year = judge_leap_year(localtime.tm_year)
43+
for m in range(1, localtime.tm_mon):
44+
day = day + month_days(m, leap_year)
45+
46+
day = day + localtime.tm_mday
47+
print("%s's age is %d years or " % (name, year), end="")
48+
print("%d months or %d days" % (month, day))

0 commit comments

Comments
 (0)