Created
June 10, 2011 11:16
-
-
Save cametan001/1018638 to your computer and use it in GitHub Desktop.
誕生日を入れたら星座と干支が出てくるプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
### http://www.python.jp/doc/2.5/lib/node85.html を参照 | |
from datetime import date | |
from time import strptime | |
class seizaAndEto: | |
def __init__(self): | |
### http://ja.wikipedia.org/wiki/%E5%B9%B2%E6%94%AF#.E5.B9.B4.E3.81.AE.E5.B9.B2.E6.94.AF を参照 | |
self.jikkan = { 0 : '庚', 1 : '辛', 2 : '壬', 3 : '癸', 4 : '甲', \ | |
5 : '乙', 6 : '丙', 7 : '丁', 8 : '戊', 9 : '己' } | |
self.junishi = { 0 : '申', 1 : '酉', 2 : '戌', 3 : '亥', \ | |
4 : '子', 5 : '丑', 6 : '寅', 7 : '卯', \ | |
8 : '辰', 9 : '巳', 10 : '午', 11 : '未' } | |
### http://www.ipc.hokusei.ac.jp/~z00104/delphi/srclister2.pl?uranai.pas:41:95:blue を参照 | |
self.seiza = { 1 : '山羊座', 2 : '水瓶座', 3 : 'うお座', 4 : '牡羊座', \ | |
5 : '牡牛座', 6 : '双子座', 7 : 'かに座', 8 : '獅子座', \ | |
9 : '乙女座', 10 : '天秤座', 11 : 'さそり座', 12 : '射手座' } | |
self.printSeizaAndEto() | |
def printSeizaAndEto(self): | |
print '生年月日を入力します。' | |
year = raw_input('生まれた年を入力してください : ') | |
month = raw_input('生まれた月を入力してください : ') | |
day = raw_input('生まれた日を入力してください : ') | |
s = "%s-%s-%s" % (year, month, day) | |
dobj= date(*strptime(s, "%Y-%m-%d")[0:3]) | |
self.year, self.month, self.day = dobj.year, dobj.month, dobj.day | |
print "生年月日: %s" % dobj | |
print '星座: %s' % (self.seizaHantei()) | |
print '干支: %s' % (self.etoHantei()) | |
def seizaHantei(self): | |
if self.day > 22: | |
if self.month == 12: | |
return self.seiza[1] | |
else: | |
return self.seiza[self.month + 1] | |
else : | |
return self.seiza[self.month] | |
def etoHantei(self): | |
return self.jikkan[self.year % 10] + self.junishi[self.year % 12] | |
if __name__ == '__main__': | |
v = seizaAndEto() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment