mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 14:01:12 +00:00
Merge pull request #418 from devtayade/master
Added age calculator script- issue solved #417
This commit is contained in:
commit
7a94dc72f9
|
@ -138,6 +138,14 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
||||||
<sub><b>Khushi Jha</b></sub>
|
<sub><b>Khushi Jha</b></sub>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
<td align="center">
|
||||||
|
<a href="https://github.com/Khushi260">
|
||||||
|
<img src="https://avatars.githubusercontent.com/u/94845508?v=4" width="100;" alt="Khushi260"/>
|
||||||
|
<br />
|
||||||
|
<sub><b>Khushi Jha</b></sub>
|
||||||
|
</a>
|
||||||
|
</td></tr>
|
||||||
|
<tr>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<a href="https://github.com/yunghog">
|
<a href="https://github.com/yunghog">
|
||||||
<img src="https://avatars.githubusercontent.com/u/41548444?v=4" width="100;" alt="yunghog"/>
|
<img src="https://avatars.githubusercontent.com/u/41548444?v=4" width="100;" alt="yunghog"/>
|
||||||
|
|
48
scripts/Calculate_your_age_script/script.py
Normal file
48
scripts/Calculate_your_age_script/script.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import time
|
||||||
|
from calendar import isleap
|
||||||
|
|
||||||
|
# judge the leap year
|
||||||
|
def judge_leap_year(year):
|
||||||
|
if isleap(year):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# returns the number of days in each month
|
||||||
|
def month_days(month, leap_year):
|
||||||
|
if month in [1, 3, 5, 7, 8, 10, 12]:
|
||||||
|
return 31
|
||||||
|
elif month in [4, 6, 9, 11]:
|
||||||
|
return 30
|
||||||
|
elif month == 2 and leap_year:
|
||||||
|
return 29
|
||||||
|
elif month == 2 and (not leap_year):
|
||||||
|
return 28
|
||||||
|
|
||||||
|
|
||||||
|
name = input("input your name: ")
|
||||||
|
age = input("input your age: ")
|
||||||
|
localtime = time.localtime(time.time())
|
||||||
|
|
||||||
|
year = int(age)
|
||||||
|
month = year * 12 + localtime.tm_mon
|
||||||
|
day = 0
|
||||||
|
|
||||||
|
begin_year = int(localtime.tm_year) - year
|
||||||
|
end_year = begin_year + year
|
||||||
|
|
||||||
|
# calculate the days
|
||||||
|
for y in range(begin_year, end_year):
|
||||||
|
if (judge_leap_year(y)):
|
||||||
|
day = day + 366
|
||||||
|
else:
|
||||||
|
day = day + 365
|
||||||
|
|
||||||
|
leap_year = judge_leap_year(localtime.tm_year)
|
||||||
|
for m in range(1, localtime.tm_mon):
|
||||||
|
day = day + month_days(m, leap_year)
|
||||||
|
|
||||||
|
day = day + localtime.tm_mday
|
||||||
|
print("%s's age is %d years or " % (name, year), end="")
|
||||||
|
print("%d months or %d days" % (month, day))
|
Loading…
Reference in New Issue
Block a user