|
|
发表于 2022-1-5 11:26:55
|
显示全部楼层
这个可以不
- def cal(date):
- count = 0
- # 存放每月的天数
- a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 平年
- b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 闰年
- # 数据分割
- if (len(date.split("/")) == 3):
- year, month, day = date.split("/")
- else:
- year, _ = date.split("年")
- month, _ = _.split("月")
- day = _[:-1]
- # 判断是平是润
- if int(year) % 4 == 0:
- ch = b
- else:
- ch = a
- # 先将 n 月前的先加起来
- for i in ch[int(month)-2:]:
- if int(month) == 1:
- break
- count += i
- count += int(day)
- print(f"现在是{year}的第", end="")
- return count
- date = input("请输入日期(2019/12/12或2019年2月2日)")
- result = cal(date)
- print(f"{result}天")
复制代码 |
|