# 請先使用命令 pip install sxtwl 安裝依賴庫後,再執行以下腳本 import sxtwl ymc = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十" ,"冬", "臘"] rmc = ["初一", "初二", "初三", &qu ...
# 請先使用命令 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/
輸了你,贏了世界又如何...