日期计算器:计算某年某月某日是这一年的第几天
以下是Python代码实现:
year = int(input('请输入年份:'))
month = int(input('请输入月份:'))
day = int(input('请输入日期:'))
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# 判断是否为闰年
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
days_in_month[1] = 29
# 计算天数
day_count = sum(days_in_month[:month-1]) + day
print('这是{}年的第{}天'.format(year, day_count))
请用户分别输入年、月、日,程序会自动计算出这一天是这一年的第几天,并以'这是xxxx年的第xx天'的格式输出结果。
原文地址: http://www.cveoy.top/t/topic/qvbY 著作权归作者所有。请勿转载和采集!