From 3d2bdf6b36da4bde0441bc60a5f3425dd7b41fe2 Mon Sep 17 00:00:00 2001 From: unknown <1594919656@qq.com> Date: Tue, 9 Apr 2024 11:02:52 +0800 Subject: [PATCH] xin zeng get_days function --- Day31-35/code/mycal.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Day31-35/code/mycal.py b/Day31-35/code/mycal.py index 8a5fc25..fb4ec91 100755 --- a/Day31-35/code/mycal.py +++ b/Day31-35/code/mycal.py @@ -39,6 +39,21 @@ def main(): w = 0 print() +def get_days(year, month): + """ + 获取指定年份和月份的天数 + """ + if month in {1, 3, 5, 7, 8, 10, 12}: + return 31 + elif month in {4, 6, 9, 11}: + return 30 + elif month == 2: + if is_leap(year): + return 29 + else: + return 28 + else: + return None # 对于非法的月份返回 None if __name__ == '__main__': main()