Files
2025PY/day11/04-作业.py
2025-05-22 16:50:44 +08:00

36 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 一.输入一个日期,判断这个日期是这一年的第几天 例如: 2016/02/11计算后结果为42
# 2016/02/11 31(1月) + 11(2月) = 42
# 2000/05/01 31(1月) + 29(2月) + 31(3月) + 30(4月) + 1(5月) = 122
# 分析
# 1.分别输出年月日
# 2.区分大月1,3,5,7,8,10,12 大月(31)
# 3.区分小月4,6,9,11 小月(2)
# 4.区分闰年2月(闰年29) (平年28)
# 代码
# 分别输出年月日
# year = int(input('请输入四位的年份:'))
# month = int(input('请输入月份:'))
# day = int(input('请输入今天是几号:'))
# result = 0 # 存储结果
# result += day # 先统计day
# 通过条件统计大月,满足条件+31天
# for m in range(1,month): # 这里不包括month本身
# if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10: # 满足大月的条件
# result += 31
# else: # 视为小月(2月也被视为小月)
# result += 30
# 根据上面的代码描述将2月也纳入小月这样结果就扩大了1或者2(1月要么28要么29)
# 根据闰年的条件进行减法运算,闰年-1非闰年-2(前面将2月变成30天)
# 主要前提月份一定要大于2
# if month > 2:
# if (year % 4 == 0 and year % 100 !=0) or (year % 400 ==0): # 闰年的条件
# result -= 1
# else :
# result -= 2
# print(f'你输入的年月日是{year}-{month}-{day} , 他是这一年的{result}天')