Ⅰ 澶╁共鍦版敮涓囱兘璁$畻鍏寮忥纴澶╁共鍦版敮镄勭畻娉
鎻愯捣澶╁共鍦版敮涓囱兘璁$畻鍏寮忥纴澶у堕兘鐭ラ亾锛屾湁浜洪梾澶╁共鍦版敮镄勭畻娉曪纴鍙﹀栵纴杩樻湁浜烘兂闂1993骞达纴鐢ㄥ共鏀绾骞存槸浠涔堟椂鍊欙纴镐庝箞璁$畻镄勶纴鍏蜂綋鍏寮忥纴浣犵煡阆撹繖鏄镐庝箞锲炰簨锛熷叾瀹炴眰澶╁共鍦版敮镄勮$畻鏂规硶锛屼笅闱㈠氨涓璧锋潵鐪嬬湅澶╁共鍦版敮镄勭畻娉曪纴甯屾湜鑳藉熷府锷╁埌澶у讹紒
澶╁共锛氱敳銆佷箼銆佷笝銆佷竵銆佹垔銆佸繁銆佸筜銆佽緵銆佸,銆佺櫢
鍦版敮锛氩瓙銆佷笐銆佸瘏銆佸嵂銆佽景銆佸烦銆佸崃銆佹湭銆佺敌銆侀厜銆佹垖銆佷亥鍦版敮链夊皬鏁扮偣镄勬庝箞绠椼
澶╁共=锛埚勾浠-3锛/10钬︹︿綑鏁颁綑鏁颁负鍑犲氨鏁板嚑涓
鍦版敮=锛埚勾浠-3锛/12钬︹︿綑鏁板悓涓
姣斿备粖骞村ぉ骞插湴鏀链姝g‘镄勭畻娉曘
锛-3锛/10钬︹︿綑鏁颁负0鏁板崄涓灏辨槸锏
锛-3锛/12钬︹︿綑鏁颁负6鏁板叚涓鏄宸
𨱒ユ簮娴呰
鐩镐紶镞╁湪鍏鍏冨墠骞达纴浜庝腑鍗庡嬬栭粍甯濆缓锲芥椂锛屽懡澶ф尃姘忔帰瀵熷ぉ鍦颁箣姘旀満锛屾帰绌朵簲琛屻
涓浜涘﹁呬粠涓锲戒笂鍙ょ殑澶忎唬甯濈帇涓栫郴鍜屽晢浠f堡鐜嬩互涓嬫墍链夊笣鐜嬬殑钖嶅瓧涓锛屾帰绌跺崄澶╁共涓镄勫瓧宸茶鐢ㄤ簬杩欎竴鐗规湁鐜拌薄銆傞儜鏂囧厜鍦ㄦ墍镢椼娄腑锲藉ぉ鏂囧︽簮娴併嬩竴涔︿腑璁や负锛屽崄澶╁共璧锋簮浜庝腑锲藉彜浠g静鍜屸灭敓鍗佹棩钬濈殑绁炶瘽锛屾槸鍗佽繘浣嶆硶姒傚康鍦ㄧ邯镞朵腑镄勫弽鏄狅纴搴斿綋浜х敓浜庢笖鐚庢椂浠g殑铡熷嬶绂钬滃崄浜屽湴鏀钬濆垯鐢卞父缇测灭敓链埚崄链変簩钬濈殑绁炶瘽婕斿彉钥屾潵锛屼骇鐢熶簬娈峰晢涔嫔墠锛屽悗阃愭笎婕斿彉涓哄崄浜岃景銆傛墍浠ワ纴閮戞枃鍏夋帹鏂锛气滃崄浜屾敮瀹滀箮鏄澶忎汉镄勫垱浣溿傗
闄堥伒濡鍦ㄣ娄腑锲藉ぉ鏂囧﹀彶銆嬩腑鎸囧嚭锛屸滃湪锲涘崈澶氩勾鍓岖殑澶忎唬锛屽彲鑳藉凡链夊共鏀浜х敓浜嗏濄傛潨鐭崇劧绛夊垯鍦ㄧ紪镢楃殑銆娄腑锲界戝︽妧链鍙茬裤嬩竴涔︿腑锛屼富寮犲忎唬宸叉湁鍗佸ぉ骞茬邯镞ユ硶锛屽晢浠e湪澶忎唬澶╁共绾镞ョ殑锘虹涓婏纴杩涗竴姝ヤ娇鐢ㄥ共鏀绾娉曪纴浠庤屾妸鍗佸ぉ骞插拰鍗佷簩鍦版敮閰嶅悎鍦ㄤ竴璧峰舰鎴愬叚鍗佸惊鐜镄勭邯镞ユ硶銆傚ぉ骞插湴鏀鎸囨爣鍏寮忋
澶х害鍦ㄦ垬锲芥汤骞达纴渚濇嵁钖勫浗鍙插畼闀挎湡绉绱涓嬫潵镄勬潗鏂欑紪鎴愮殑鍙蹭功銆娄笘链銆嬭达细钬滃规垚浣滃巻锛屽ぇ妗′綔鐢插瓙钬濓纴銆婂皻涔︽d箟銆嬭В閲婅达细钬滀簩浜虹殕榛勫笣涔嬭噜锛岀洊镊榛勫笣浠ユ潵锛屽嬬敤鐢插瓙绾镞ワ纴姣忓叚鍗佹棩钥岀敳瀛愪竴锻ㄢ濄傜湅鏀鏄澶ф鍒涘埗镄勶纴澶ф钬滈噰浜旇屼箣𨱍咃纴鍗犳枟链烘墍寤猴纴濮嬩綔鐢蹭箼浠ュ悕镞ワ纴璋扑箣骞诧绂浣滃瓙涓戜互钖嶆湀锛岃皳涔嬫灊锛屾湁浜嬩簬澶╁垯鐢ㄦ棩锛屾湁浜嬩簬鍦板垯鐢ㄦ湀锛屼箣鍒锛屾晠链夋灊骞插悕涔熴傗
骞叉敮绾骞存硶锛屾垜锲戒紶缁熺殑绾骞存柟娉曘
1锛庡共鍜屾敮镄勫惈涔夛细骞叉敮鏄澶╁共锛屽湴鏀镄勫悎绉般
鍗佸ぇ澶╁共锛氱敳涓佸筜锏
鍗佷簩鍦版敮锛氩瓙锛堥紶)
涓(鐗)
瀵咃纸铏庯级
鍗锛埚厰锛
杈帮纸榫欙级
宸筹纸铔囷级
鍗堬纸椹锛変换镒忔棩骞叉敮宸х畻娉曘
链锛堢緤锛
鐢筹纸鐚达级
閰夛纸楦★级
鎴岋纸镫楋级骞叉敮绾骞存硶绠渚跨畻娉曞叕寮忋
浜ワ纸鐚锛
2锛庡共鍜屾敮缁勫悎钖庣敤浜庣邯骞淬傚嵆锛氩皢鍗佸ぉ骞插拰鍗佷簩鍦版敮鎸夐‘搴忔惌閰岖粍钖堟垚骞叉敮锛岀敤浜庣邯骞淬傛寜姝ゆ帓娉曪纴鍙鏋勬垚60骞叉敮锛埚嵆涓轰竴鑺辩敳锛夈傜画鎺掍笅铡诲张灏嗘仮澶嶅师鐘讹纴锻ㄨ屽嶅嬶纴姘告棤姝㈠敖銆傚崄澶╁共镓鏀銆
3銆佽$畻鏂规硶濡备笅锛氩筜杈版棩濂冲懡鐭銆
锛1锛夊皢鍗佸ぇ澶╁共銆佸崄浜屽湴鏀缂栧彿銆傚备笅锛氢笝宸卞,瀛愬嵂鍗堥厜澶╁共鍦版敮镞ユ湡璁$畻鍣ㄣ
锛2锛夎$畻镞讹纴骞翠綅镄勬暟瀵瑰簲澶╁共镄勭紪鍙枫佺敤骞存暟闄や互12锛屽缑鍒扮殑浣欐暟瀵瑰簲鍦版敮镄勭紪鍙凤纴钖堣捣𨱒ュ氨鏄璇ュ勾镄勫共鏀绾骞存硶銆傚ぉ骞插湴鏀镄勮$畻鏂规硶銆
濡傚勾锛氢綅鏄1锛屽瑰簲镄勫ぉ骞茬殑缂栧彿灏辨槸钬滆緵钬濓纴鍐岖敤闄や互12寰楀埌浣7锛屽瑰簲鍦版敮缂栧彿涓衡滃嵂钬濆悎璧锋潵鍗冲勾涓衡滆緵鍗钬濆勾銆傚埯涓铡嗗彶镞堕棿璁$畻鍏寮忋
浠ヤ笂灏辨槸涓庡ぉ骞插湴鏀镄勭畻鍏冲唴瀹癸纴鏄鍏充簬澶╁共鍦版敮镄勭畻娉旷殑鍒嗕韩銆傜湅瀹屽ぉ骞插湴鏀涓囱兘璁$畻鍏寮忓悗锛屽笇链涜繖瀵瑰ぇ瀹舵湁镓甯锷╋紒
Ⅱ python1900锝2031骞,杈揿嚭姣忓勾镄勫ぉ骞层佸湴鏀,鍒ゆ柇鏄钖﹂棸骞村苟缁熻¢棸骞寸殑涓鏁帮纻
# 瀹氢箟澶╁共鍜屽湴鏀镄勫垪琛╰iangan = ["鐢","涔","涓","涓","鎴","宸","搴","杈","澹","锏"]
di = ["瀛","涓","瀵","鍗","杈","宸","鍗","链","鐢","閰","鎴","浜"]# 瀹氢箟涓涓鍑芥暟锛屽垽鏂鏄钖︿负闂板勾def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: return True
else: return False# 鍒濆嫔寲闂板勾镄勪釜鏁颁负闆秎eap_count = 0# 阆嶅巻1900鍒2031骞达纴杈揿嚭姣忓勾镄勫ぉ骞插湴鏀鍜屾槸钖︿负闂板勾for year in range(1900,2032): # 璁$畻澶╁共鍜屽湴鏀镄勭储寮曪纴娉ㄦ剰瑕佸噺铡1锛屽洜涓哄垪琛ㄤ粠闆跺紑濮
tiangan_index = (year - 1900) % 10 - 1
di_index = (year - 1900) % 12 - 1
# 杈揿嚭姣忓勾镄勫ぉ骞插湴鏀
print(f"{year}骞存槸{tiangan[tiangan_index]}{di[di_index]}骞", end=" ")
# 鍒ゆ柇鏄钖︿负闂板勾锛屽苟杈揿嚭缁撴灉
if is_leap_year(year): print("鏄闂板勾") # 绱锷犻棸骞寸殑涓鏁
leap_count += 1
else: print("涓嶆槸闂板勾")# 杈揿嚭镐诲叡链夊氩皯涓闂板勾 print(f"浠1900鍒2031骞达纴涓鍏辨湁{leap_count}涓闂板勾")
Ⅲ 用Python计算年份属于哪个天干地支 源代码
这个是我原创的,如果有考虑不周的地方可以交流一下:
y=int(input("请输入公历年份(公元前请加“-”):"))
t=(y-4)%60%10
d=(y-4)%60%12
T=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
D=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
print("{}年为:农历{}{}年".format(y,T[t],D[d]))
运行结果: