# 请先使用命令 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://blog.csdn.net/m0_53623159/article/details/121843476
https://www.cnblogs.com/Eleven-Liu/p/11142703.html
https://pypi.org/project/sxtwl/
标签:公历,csrq,csn,查找,print,生日,day,sxtwl From: https://www.cnblogs.com/xwgli/p/17327265.html