VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • 查找自己农历生日与公历生日在同一天的年份

 
复制代码
# 请先使用命令 pip install sxtwl 安装依赖库后,再执行以下脚本

import sxtwl

ymc = ["", "", "", "", "", "", "", "", "", "" ,"", ""]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]

csrq = sxtwl.fromSolar(1990, 1, 1) # 在此填写自己的公历出生日期

csn = csrq.getSolarYear()
csgly = csrq.getSolarMonth()
csglr = csrq.getSolarDay()
csnly = csrq.getLunarMonth()
csnlr = csrq.getLunarDay()

czdns = 100 # 从出生年开始,遍历查找多少年
tytdcs = 0  # 记录同一天的次数

print("==================================================")
for year in range(csn, csn + czdns):
    day = sxtwl.fromSolar(year, csgly, csglr)
    if day.getLunarMonth() == csnly and day.getLunarDay() == csnlr:
        tytdcs += 1
        print("", tytdcs, "次,公历与农历生日在同一天")
        if((year - csn) == 0):
            print("我出生啦!")
        else:
            print("", (year - csn), "")
        print("公历:" + str(day.getSolarYear()) + "" + str(day.getSolarMonth()) + "" + str(day.getSolarDay()) + "")
        print("农历:" + ymc[day.getLunarMonth()-1] + "" + rmc[day.getLunarDay()-1])
        print("==================================================")
复制代码



 



出处:https://www.cnblogs.com/xwgli/p/17327265.html

相关教程