首先输入出生年月日与现在的年月日
#提取身份证中的年月日,输入现在年月日
a = input('请输入身份证:');
b = a[6:10]
c = a[10:12]
d = a[12:14]
print('您出生于%s年%s月%s日'%(b,c,d))
year = input('请输入现在是哪一年:')
month = input('请输入现在是哪一月:')
date = input('请输入现在是哪一日:')
判断从出生到现在有几个闰年,先假定所有天数都是365天,最后再加上闰年年数
t = 0
for n in range(int(b),int(year)):
if n%4 !=0:
continue
t = t+1
计算今天与生日相差几天,加在总天数里
other_day = 0
now_day = 0
month_day=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year_day = (int(year)-int(b))*365 #估算的总天数
#生日天数
for g in range(int(c)-1):
other_day = other_day+month_day[g]
other_day = other_day+int(d)
#现在天数
for f in range(int(month)-1):
now_day = now_day + month_day[f]
now_day = now_day + int(date)last_day = now_day - other_day
all_day = last_day+year_day+ t #得到相差天数
print("你已出生%d天”%(all_day))