python纳甲装卦

python纳甲装卦用python为六爻纳甲写一个自动装卦的程序设计思路:因为初学python设计的比较简单,用面向过程的方法将每一爻所代表的属性存于一个列表,同时六爻组成一个列表,即一个二维列表存储卦的信息

用python为六爻纳甲写一个自动装卦的程序
设计思路:因为初学python设计的比较简单,用面向过程的方法
将每一爻所代表的属性存于一个列表,同时六爻组成一个列表,即一个二维列表存储卦的信息。变卦类似。
输入需要按提示按序输入每一爻字的个数,如图:
dos窗口
输出如图:
标题为复卦所在宫 前卦名,如果存在变卦则写全名
归魂与游魂卦会在名字后边标注
左侧为前卦,前卦左侧数字为所摇出的卦,信息为变爻的信息,相应数字为0或3,右侧为该卦的信息
右侧为后卦,后卦左侧信息已写全
由于解挂时需要用干支纪法得到当前日期,但好像没有发现该功能的模块,所以只是留了一个连接,方便查询
不过有看过一个python的获得八字程序,各位如果想添加日期功能可以参考获取干支纪年
dos窗口代码如下,具体见注释

#纳甲装卦
from __future__ import print_function#避免自动换行
trigram = [[0 for col in range(10)] for row in range(6)]  
c_trigram = [[0 for col in range(10)] for row in range(6)] #变卦 0判断是否要输出 1变卦化码 2地支 3五行 4用神 5变卦化码符号
flag=0#是否有变卦

#输入原卦,获得原卦二进制码,获得符号,up_t,down_t
n=0
while n<6:
    trigram[5-n][0]=input("请输入第%s爻的字数:" % (n+1))#0原卦 1地支 2五行 3用神 4原卦化码 5原卦化码符号 
    n=n+1


n=0
while n<6:
    if trigram[n][0]=="1":
        trigram[n][4]=0
        trigram[n][5]="—— ——"#vs code中想要对齐要去两空格 dos正好
        c_trigram[n][0]=False
        c_trigram[n][1]=0
        c_trigram[n][5]="—— ——"#变卦化码符号
    elif trigram[n][0]=="2":
        trigram[n][4]=1
        trigram[n][5]="——————"
        c_trigram[n][0]=False
        c_trigram[n][1]=1
        c_trigram[n][5]="——————"
    elif trigram[n][0]=="3":
        flag=1
        trigram[n][4]=0
        trigram[n][5]="—— ——"#vs code中想要对齐要去两空格 dos正好
        c_trigram[n][0]=True
        c_trigram[n][1]=1
        c_trigram[n][5]="——————"
    elif trigram[n][0]=="0":
        flag=1
        trigram[n][4]=1
        trigram[n][5]="——————"
        c_trigram[n][0]=True
        c_trigram[n][1]=0
        c_trigram[n][5]="—— ——"
    n=n+1


up_t=4*trigram[2][4]+2*trigram[1][4]+trigram[0][4]#外卦#不该是0,应该是1或0
down_t=4*trigram[5][4]+2*trigram[4][4]+trigram[3][4]#内卦

c_up_t=4*c_trigram[2][1]+2*c_trigram[1][1]+c_trigram[0][1]#变卦外卦
c_down_t=4*c_trigram[5][1]+2*c_trigram[4][1]+c_trigram[3][1]#变卦内卦





#安装地支
#Earthly Branches 地支
#>>> n=789
#>>> "789"==str("%d" % n)
#True
EB={ 
   "107":"戌土" ,"102":"子水" ,"101":"寅木" ,"104":"戌土" ,"103":"卯木" ,"105":"巳火" ,"100":"酉金" ,"106":"未土" ,
    "117":"申金" ,"112":"戌土" ,"111":"子水" ,"114":"申金" ,"113":"巳火" ,"115":"未土" ,"110":"亥水" ,"116":"酉金" ,
    "127":"午火" ,"122":"申金" ,"121":"戌土" ,"124":"午火" ,"123":"未土" ,"125":"酉金" ,"120":"丑土" ,"126":"亥水" ,
    "237":"辰土" ,"232":"午火" ,"231":"申金" ,"234":"辰土" ,"233":"酉金" ,"235":"亥水" ,"230":"卯木" ,"236":"丑土" ,
    "247":"寅木" ,"242":"辰土" ,"241":"午火" ,"244":"寅木" ,"243":"亥水" ,"245":"丑土" ,"240":"巳火" ,"246":"卯木" ,
    "257":"子水" ,"252":"寅木" ,"251":"辰土" ,"254":"子水" ,"253":"丑土" ,"255":"卯木" ,"250":"未土" ,"256":"巳火" }
    #第一位1表外卦,2表内卦 第二位表从上向下数第几爻 第三位二进制表示的宫
n=0
while n<6:
    if n<3:
        x=100+10*n+int(up_t)#宫
    else:
        x=200+10*n+int(down_t)#宫
    trigram[n][1]=EB[str("%d" % x)]
    n=n+1

n=0
while n<6:
    if n<3:
        x=100+10*n+int(c_up_t)#宫
    else:
        x=200+10*n+int(c_down_t)#宫
    c_trigram[n][2]=EB[str("%d" % x)]
    n=n+1




#装五行
EB_elt={ 
   "子水":2 ,"丑土":5 ,"寅木":3 ,"卯木":3 ,"辰土":5 ,"巳火":4 ,
        "午火":4 ,"未土":5 ,"申金":1 ,"酉金":1 ,"戌土":5 ,"亥水":2 }#金1 水2 木3 火4 土5
n=0
while n<6:
    trigram[n][2]=EB_elt[trigram[n][1]]
    n=n+1

n=0
while n<6:
    c_trigram[n][3]=EB_elt[c_trigram[n][2]]
    n=n+1







#装六亲,定宫,定名
EB_elt_ugod={ 
   "-4":"父母" ,"1":"父母" ,
             "0":"兄弟" ,
             "-1":"子孙" ,"4":"子孙" ,
             "-3":"官鬼" ,"2":"官鬼" ,
             "-2":"妻财" ,"3":"妻财" }
up_dowm_t=10*down_t+up_t+100 #避免0开头转字符串不适应 复卦的代表数
c_up_dowm_t=10*c_down_t+c_up_t+100 #变卦的代表数
temple_name_elt={ 
   "177":["乾","乾为天",1,0,3],"137":["乾","天风姤",1,5,2],"117":["乾","天山遁",1,4,1],"107":["乾","天地否",1,3,0],
                 "103":["乾","风地观",1,2,5],"101":["乾","山地剥",1,1,4],"105":["乾","火地晋(游魂)",1,2,5],"175":["乾","火天大有(归魂)",1,3,0],
                 "122":["坎","坎为水",2,0,3],"162":["坎","水泽节",2,5,2],"142":["坎","水雷屯",2,4,1],"152":["坎","水火既济",2,3,0],
                 "156":["坎","泽火革",2,2,5],"154":["坎","雷火丰",2,1,4],"150":["坎","地火明夷(游魂)",2,2,5],"102":["坎","地水师(归魂)",2,3,0],
                 "111":["艮","艮为山",5,0,3],"151":["艮","山火贲",5,5,2],"171":["艮","山天大畜",5,4,1],"161":["艮","山泽损",5,3,0],
                 "165":["艮","火泽睽",5,2,5],"167":["艮","天泽履",5,1,4],"163":["艮","风泽中孚(游魂)",5,2,5],"113":["艮","风山渐(归魂)",5,3,0],
                 "144":["震","震为雷",3,0,3],"104":["震","雷地豫",3,5,2],"124":["震","雷水解",3,4,1],"134":["震","雷风恒",3,3,0],
                 "130":["震","地风升",3,2,5],"132":["震","水风井",3,1,4],"136":["震","泽风大过(游魂)",3,2,5],"146":["震","泽雷随(归魂)",3,3,0],
                 "133":["巽","巽为风",3,0,3],"173":["巽","风天小畜",3,5,2],"153":["巽","风火家人",3,4,1],"143":["巽","风雷益",3,3,0],
                 "147":["巽","天雷无妄",3,2,5],"145":["巽","火雷噬嗑",3,1,4],"141":["巽","山雷颐(游魂)",3,2,5],"131":["巽","山风蛊(归魂)",3,3,0],
                 "155":["离","离为火",4,0,3],"115":["离","火山旅",4,5,2],"135":["离","火风鼎",4,4,1],"125":["离","火水未济",4,3,0],
                 "121":["离","山水蒙",4,2,5],"123":["离","风水涣",4,1,4],"127":["离","天水讼(游魂)",4,2,5],"157":["离","天火同人(归魂)",4,3,0],
                 "100":["坤","坤为地",5,0,3],"140":["坤","地雷复",5,5,2],"160":["坤","地泽临",5,4,1],"170":["坤","地天泰",5,3,0],
                 "174":["坤","雷天大壮",5,2,5],"176":["坤","泽天夬",5,1,4],"172":["坤","水天需(游魂)",5,2,5],"102":["坤","水地比(归魂)",5,3,0],
                 "166":["兑","兑为泽",1,0,3],"126":["兑","泽水困",1,5,2],"106":["兑","泽地萃",1,4,1],"116":["兑","泽山咸",1,3,0],
                 "112":["兑","水山蹇",1,2,5],"110":["兑","地山谦",1,1,4],"114":["兑","雷山小过(游魂)",1,2,5],"164":["兑","雷泽归妹(归魂)",1,3,0]}

my_elt=temple_name_elt[str("%d" % up_dowm_t)][2] #卦所在宫的五行


shi=temple_name_elt[str("%d" % up_dowm_t)][3]#世爻
ying=temple_name_elt[str("%d" % up_dowm_t)][4]#应爻

n=0
while n<6:
    trigram[n][3]=EB_elt_ugod[str("%d" % (my_elt-trigram[n][2]))]
    n=n+1


n=0
while n<6:
    c_trigram[n][4]=EB_elt_ugod[str("%d" % (my_elt-c_trigram[n][3]))]
    n=n+1


#世应



#打印结果
print("\n\n\n")
print(temple_name_elt[str("%d" % up_dowm_t)][0]+"宫",temple_name_elt[str("%d" % up_dowm_t)][1],end='')#不希望这里有回车
if flag==1:
    print("之"+temple_name_elt[str("%d" % c_up_dowm_t)][1])
print("\n")

#打印日期


n=0
while n<6:
    if c_trigram[n][0]:
        print(c_trigram[n][4],c_trigram[n][2]," ",end=' ')#不希望这里有回车
    else:
        print(" ",end=' ')
    print(trigram[n][0],trigram[n][5]," ",trigram[n][3],trigram[n][1],end=' ')
    if n==shi:
        print(" 世爻",end=' ')
    elif n==ying:
        print(" 应爻",end=' ')
    else:
        print(" ",end=' ')
    if flag==1:
        print(" ",end=' ')#完整变卦
        print(c_trigram[n][4],c_trigram[n][2]," ",end=' ')
        print(c_trigram[n][5])
    print("\n")
    
    n=n+1



print("DOS窗口查询万年历请输入:\n")
print("start explorer https://wannianrili.51240.com/")

今天的文章python纳甲装卦分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/63699.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注