0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonで書く相性診断プログラム

Last updated at Posted at 2019-11-14

pythonの相性診断のプログラム

from datetime import date
from time import strptime

new={'双子座':'水瓶座','牡牛座':'乙女座','さそり座':'うお座',\
'獅子座':'射手座','やぎ座':'乙女座','かに座':'牡羊座'}

class seizaandeto:
    def __init__(self):
        self.seiza={1:'やぎ座',2:'水瓶座',3:'うお座',4:'牡羊座',5:'牡牛座',\
                      6:'双子座',7:'かに座',8:'獅子座',9:'乙女座',10:'天秤座',\
                      11:'さそり座',12:'射手座'}

        self.printSeizaandeto()

    def printSeizaandeto(self):
        print('生年月日を入力します。')
        year=input('生まれた年を入力してください。')
        month=input('生まれた月を入力してください。')
        day=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
        x=self.seizaHantei()
        print('あなたと相性がいいのは' + new[x] + 'です。')
        print("生年月日:%s" % dobj)
        print('星座:%s' % (self.seizaHantei()))

    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]

if __name__=='__main__':
    v=seizaandeto()


作り方
①始めに星座の全ての情報を持った集合を作る
②キーを数字、要素を星座情報にした辞書を作り生年月日を入力させるメソッドに飛ばす
③星座を特定する
④相性を適当に決めて出力する

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?