# -*- coding: utf-8 -*-
# 简述:要求输入某年某月某日
# 提问:求判断输入日期是当年中的第几天?
def which_day(year,month,day):
list=[31,28,31,30,31,30,31,31,30,31,30,31]
whichday=0
if (year%4)==0 and (year%100)!=0 or (year%400)==0:
list[1]=29
for i in range(1,month):
if month == 1:
print day
whichday=whichday+list[i-1]
whichday=whichday+day
print whichday
if __name__ == "__main__":
year=int(raw_input("请输入年份:"))
month=int(raw_input("请输入月份:"))
day=int(raw_input("请输入天:"))
which_day(year, month, day)
运行结果:
请输入年份:2017
请输入月份:3
请输入天:31
90
总结:
1、闰年的判断为能被4整除,但不能被100整除,或者能被400整除
刚开始三者都写成了and
2、关于list[i-1]刚开始写成了i-2,对于某些时期恰好是正确的,是因为成了list[-1]时从结尾开始取值