用一个代码达到输入某人日期,则可以计算出他到今天为止存活过的天数
今天的日期按照 2020/2/16 来计算。
由于这个题目本身挺复杂,所以先实现一个更简单的题目:任意给出一个日期,给出这是这一年的第几天
- 这个代码是我第一个写的不是很聪明的办法,虽然也可以达到最终的目的,但是代码的篇幅很长,有大量不必要的部分。
year = int(input('请输入年份:'))
month = int(input('请输入月份:'))
date = int(input('请输入日期:'))
if year%4==0 and year%100!=0 or year%400==0:
ii = 29
else:
ii = 28
if month==1:
n = day
elif month==2:
n = 31+date
elif month==3:
n = 31+ii+date
elif month==4:
n = 31+ii+31+date
elif month==5:
n = 31+ii+31+30+date
elif month==6:
n = 31+ii+31+30+31+date
elif month==7:
n = 31+ii+31+30+31+30+date
elif month==8:
n = 31+ii+31+30+31+30+31+date
elif month==9:
n = 31+ii+31+30+31+30+31+31+date
elif month==10:
n = 31+ii+31+30+31+30+31+31&#