def is_leap_year(year):\n if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n return True\n else:\n return False\n\ndef day_of_year(year, month, day):\n days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n if is_leap_year(year):\n days_in_month[1] = 29\n \n total_days = 0\n for i in range(month - 1):\n total_days += days_in_month[i]\n \n total_days += day\n return total_days\n\nyear = int(input("请输入年份:"))\nmonth = int(input("请输入月份:"))\nday = int(input("请输入日期:"))\n\nresult = day_of_year(year, month, day)\nprint("{}年{}月{}日是这一年的第{}天".format(year, month, day, result))

Python 计算某年某月某日是当年的第几天 - 代码示例及详解

原文地址: https://www.cveoy.top/t/topic/pG6Y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录