06_python_练习题——查找一年之中第几天
#编写程序,判断这是这一年中的第几天?
#附加题:同时输出这是闰年不是,注意要求输入年份的格式
#程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,
#附加题:同时输出这是闰年不是,注意要求输入年份的格式
#程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,
#特殊情况,闰年且输入月份大于3时需考虑多加一天
# -*- coding:UTF-8 -*-
year = int(raw_input('Input year:'))
month = int(raw_input('Input month:'))
day = int(raw_input('Input day:'))
def isRunNian(year,month,day):
leap = 0
if(year%400 == 0) or ((year%4 == 0) and (year%100 != 0)):
leap=1
print year,"是闰年"
else:
print year,"年不是闰年"
months = (0,31,59,90,120,151,181,212,243,273,304,334)
if leap==1 :
if month==2 and 0<day<29:
pass
elif(month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12) and 0<day<32:
pass
elif (month==4 or month==6 or month==9 or month==11 ) and 0<day<31:
pass
else:
print "输入的日期错误"
return
else:
if month==2 and 0<day<30:
pass
elif (month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12) and 0<day<32:
pass
elif (month==4 or month==6 or month==9 or month==11 ) and 0<day<31:
pass
else:
print "输入的日期错误"
return
sum = months[month-1]+day
if(leap == 1) and (month > 2):
sum+=1
print "这是%d年的第%d天。"%(year,sum)
isRunNian(year,month,day)