大佬帮忙看看哪里有错误啊,新手小白留
year = int(input("请输入一个大于1990年的年份:\n"))month = int(input("请输入一个月份:\n"))
day = int(input("请输入一个日子:"))
a = year-1988
if a%4==1:
if month==1:
days=a/4*365*4+day
elif month==2:
days=a/4*365*4+31+day
elif month==3:
days=a/4*365*4+59+day
elif month==4:
days=a/4*365*4+90+day
elif month==5:
days=a/4*365*4+120+day
elif month==6:
days=a/4*365*4+151+day
elif month==7:
days=a/4*365*4+181+day
elif month==8:
days=a/4*365*4+212+day
elif month==9:
days=a/4*365*4+243+day
elif month==10:
days=a/4*365*4+273+day
elif month==11:
days=a/4*365*4+304+day
else month==12:
days=a/4*365*4+334+day
elif a%4==2:
if month==1:
days=a/4*365*4+365+day
elif month==2:
days=a/4*365*4+365+31+day
elif month==3:
days=a/4*365*4+365+59+day
elif month==4:
days=a/4*365*4+365+90+day
elif month==5:
days=a/4*365*4+365+120+day
elif month==6:
days=a/4*365*4+365+151+day
elif month==7:
days=a/4*365*4+365+181+day
elif month==8:
days=a/4*365*4+365+212+day
elif month==9:
days=a/4*365*4+365+243+day
elif month==10:
days=a/4*365*4+365+273+day
elif month==11:
days=a/4*365*4+365+304+day
else month==12:
days=a/4*365*4+365+334+day
elif a%4==3:
if month==1:
days=a/4*365*4+730+day
elif month==2:
days=a/4*365*4+730+31+day
elif month==3:
days=a/4*365*4+730+59+day
elif month==4:
days=a/4*365*4+730+90+day
elif month==5:
days=a/4*365*4+730+120+day
elif month==6:
days=a/4*365*4+730+151+day
elif month==7:
days=a/4*365*4+730+181+day
elif month==8:
days=a/4*365*4+730+212+day
elif month==9:
days=a/4*365*4+730+243+day
elif month==10:
days=a/4*365*4+730+273+day
elif month==11:
days=a/4*365*4+730+304+day
else month==12:
days=a/4*365*4+730+334+day
else a%4==0:
if month==1:
days=a/4*365*4+730+day
elif month==2:
days=a/4*365*4+730+31+day
elif month==3:
days=a/4*365*4+730+59+1+day
elif month==4:
days=a/4*365*4+730+90+1+day
elif month==5:
days=a/4*365*4+730+120+1+day
elif month==6:
days=a/4*365*4+730+151+1+day
elif month==7:
days=a/4*365*4+730+181+1+day
elif month==8:
days=a/4*365*4+730+212+1+day
elif month==9:
days=a/4*365*4+730+243+1+day
elif month==10:
days=a/4*365*4+730+273+1+day
elif month==11:
days=a/4*365*4+730+304+1+day
else month==12:
days=a/4*365*4+730+334+1+day
else后面不能跟条件,你要么换用elif,要么就删掉else后的条件
推荐替换掉else year = int(input("请输入一个大于1990年的年份:\n"))
month = int(input("请输入一个月份:\n"))
day = int(input("请输入一个日子:"))
a = year-1988
if a%4==1:
if month==1:
days=a/4*365*4+day
elif month==2:
days=a/4*365*4+31+day
elif month==3:
days=a/4*365*4+59+day
elif month==4:
days=a/4*365*4+90+day
elif month==5:
days=a/4*365*4+120+day
elif month==6:
days=a/4*365*4+151+day
elif month==7:
days=a/4*365*4+181+day
elif month==8:
days=a/4*365*4+212+day
elif month==9:
days=a/4*365*4+243+day
elif month==10:
days=a/4*365*4+273+day
elif month==11:
days=a/4*365*4+304+day
else: #这里修改
days=a/4*365*4+334+day
elif a%4==2:
if month==1:
days=a/4*365*4+365+day
elif month==2:
days=a/4*365*4+365+31+day
elif month==3:
days=a/4*365*4+365+59+day
elif month==4:
days=a/4*365*4+365+90+day
elif month==5:
days=a/4*365*4+365+120+day
elif month==6:
days=a/4*365*4+365+151+day
elif month==7:
days=a/4*365*4+365+181+day
elif month==8:
days=a/4*365*4+365+212+day
elif month==9:
days=a/4*365*4+365+243+day
elif month==10:
days=a/4*365*4+365+273+day
elif month==11:
days=a/4*365*4+365+304+day
else: #这里修改
days=a/4*365*4+365+334+day
elif a%4==3:
if month==1:
days=a/4*365*4+730+day
elif month==2:
days=a/4*365*4+730+31+day
elif month==3:
days=a/4*365*4+730+59+day
elif month==4:
days=a/4*365*4+730+90+day
elif month==5:
days=a/4*365*4+730+120+day
elif month==6:
days=a/4*365*4+730+151+day
elif month==7:
days=a/4*365*4+730+181+day
elif month==8:
days=a/4*365*4+730+212+day
elif month==9:
days=a/4*365*4+730+243+day
elif month==10:
days=a/4*365*4+730+273+day
elif month==11:
days=a/4*365*4+730+304+day
else : #这里修改
days=a/4*365*4+730+334+day
else: #这里修改
if month==1:
days=a/4*365*4+730+day
elif month==2:
days=a/4*365*4+730+31+day
elif month==3:
days=a/4*365*4+730+59+1+day
elif month==4:
days=a/4*365*4+730+90+1+day
elif month==5:
days=a/4*365*4+730+120+1+day
elif month==6:
days=a/4*365*4+730+151+1+day
elif month==7:
days=a/4*365*4+730+181+1+day
elif month==8:
days=a/4*365*4+730+212+1+day
elif month==9:
days=a/4*365*4+730+243+1+day
elif month==10:
days=a/4*365*4+730+273+1+day
elif month==11:
days=a/4*365*4+730+304+1+day
else : #还有这里
days=a/4*365*4+730+334+1+day
print("共%d天"%days) 有一说一,你这么写太罗嗦了没啥意义啊 year = int(input("请输入一个大于1990年的年份:\n"))
month = int(input("请输入一个月份:\n"))
day = int(input("请输入一个日子:"))
a = year-1988
month_list =
if a%4==1:
days = a/4*365*4+month_list+day
elif a%4==2:
days = a/4*365*4+365+month_list+day
elif a%4==3:
days = a/4*365*4+730+month_list+day
else:
if month==1:
days=a/4*365*4+730+day
elif month==2:
days=a/4*365*4+730+31+day
else:
days = a/4*365*4+730+month_list+1+day
print("共%d天"%days)
用个列表把每月之前的天数统计一下,省下好多代码 满意的话记得给个最佳哈 本帖最后由 害羞的新手 于 2020-10-14 14:21 编辑
我觉得以后还是规范化写好,比如if{.......} 错误有好几处,列举最后一处
else month==12:
days=a/4*365*4+730+334+1+day
规范的python代码规则是
else: #else后面不能带条件,意为否则
days=a/4*365*4+730+334+1+day
或者
elif month==12:
days=a/4*365*4+730+334+1+day
昨非 发表于 2020-10-14 12:54
满意的话记得给个最佳哈
谢谢啦
笨鸟学飞 发表于 2020-10-14 17:06
错误有好几处,列举最后一处
else month==12:
days=a/4*365*4+730+334+1+day
谢谢啦
页:
[1]