占星骰子的根本思路就是通過擷取随機值來确定對應的星座、宮位和行星。那麼我們隻需要使用random來寫主函數就可以。
主函數:
def ZhanXing(self):
xingzuo,gongwei,xingxing = random.randint(0,11),random.randint(0,11),random.randint(0,11)
result = {'gongwei':self.gw[gongwei],"xingzuo":self.xz[xingzuo],"xingxing":self.xx[xingxing]}
return result
從0-11中随機生成數字,指派給星座、行星、宮位,這樣可以從12個數字中随機取一個。
初始化資源:
def __init__(self):
self.xz = ["白羊座","金牛座","雙子座","巨蟹座","獅子座","處女座","天秤座","天蠍座","射手座","摩羯座","水瓶座","雙魚座"]
self.gw = ["第一宮","第二宮","第三宮","第四宮","第五宮","第六宮","第七宮","第八宮","第九宮","第十宮","第十一宮","第十二宮"]
self.xx = ["太陽","月亮","火星","水星","木星","金星","土星","天王星","海王星","冥王星","南交點","北交點"]
給随機生成的數字寫明指代的星座、行星、宮位
類中對各個名詞進行解釋(解釋忽略):
__xingxing = {"太陽":'',"月亮":'',"火星":'',"水星":'',"木星":'',"金星":'',"土星":'',"天王星":'',"海王星":'',"冥王星":'',"南交點":'',"北交點":''}
__xingzuo = {"白羊座":'',"金牛座":'',"雙子座":'',"巨蟹座":'',"獅子座":'',"處女座":'',"天秤座":'',"天蠍座":'',"射手座":'',"摩羯座":'',"水瓶座":'',"雙魚座":''}
__gongwei = {"第一宮":'',"第二宮":'',"第三宮":'',"第四宮":'',"第五宮":'',"第六宮":'',"第七宮":'',"第八宮":'',"第九宮":'',"第十宮":'',"第十一宮":'',"第十二宮":''}
__jx = {"太陽":'吉',"月亮":'吉',"火星":'兇',"水星":'平',"木星":'吉',"金星":'吉',"土星":'兇',"天王星":'平',"海王星":'兇',"冥王星":'平',"南交點":'兇',"北交點":'平'}