计算自己农历生日与阳历生日属于同一天的年份和次数
#!/usr/bin/env python # 引入sxtwl模块,具体用法参考 https://pypi.org/project/sxtwl/ import sxtwl lunar = sxtwl.Lunar() ymc = ["十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十" ] rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] i=0 print("----------------------——————————————————————") for num in range(2000,2101): day = lunar.getDayBySolar(num, 7, 7) # 遍历年份,两个7表示阳历生日是7月7日 if day.Lleap: if ymc[day.Lmc] == "六" and rmc[day.Ldi] == "初六": # 假设农历生日是六月初六 i += 1 print("第",i,"次","阳历与农历生日属于同一天") print("我",num-2000,"岁") print("公历:", day.y, "年", day.m, "月", day.d, "日") print("润", ymc[day.Lmc], "月", rmc[day.Ldi], "日") print("----------------------——————————————————————") else: if ymc[day.Lmc] == "六" and rmc[day.Ldi] == "初六": i += 1 print("第", i, "次", "阳历与农历生日属于同一天") print("我", num - 2000, "岁") print("公历:", day.y, "年", day.m, "月", day.d, "日") print(ymc[day.Lmc], "月", rmc[day.Ldi], "日") print("----------------------——————————————————————")