Pythonで月齢と干支の計算
©ìîvZ\tg
↑こちらを参考にさせて頂きました。
- 月齢
from datetime import date
def moon_age(y, m, d):
mp = [0,2,0,2,2,4,5,6,7,8,9,10]
return (((y - 11) % 19) * 11 + mp[m - 1] + d) % 30
def get_today():
now = date.today()
return now.strftime("%Y/%m/%d")
today = get_today()
Y, M, D = today.split("/")
y = int(Y)
m = int(M)
d = int(D)
print "date: " + today
print "age : " + str(moon_age(y, m, d))
- 干支
def chinese_zodiac(y):
animals = ["mouse","cow","tiger","rabbit","dragon","snake"]
animals += ["horse","sheep","monkey","cock","dog","pig"]
return animals[((y - 4) % 12)]
while 1 :
y = raw_input()
# only return to exit
if y == "" :
break
print "=> " + chinese_zodiac(int(y))ひまですな〜〜。