标签:python
You are given the following information, but you may prefer to do some research for yourself.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
def IsLeapYear(year): if year%4==0: if year%100==0: if year%400==0: return 1 else: return 0 return 1 else: return 0 def MonthNumList(year): List=[31,28,31,30,31,30,31,31,30,31,30,31] if IsLeapYear(year)==1: List[1]=29 return List startDay=1 count=0 for year in range(1900,2001): monthNum=MonthNumList(year) for month in range(0,12): startDay=(startDay+monthNum[month])%7 if year>1900 and startDay==0: count=count+1 print(count)
标签:python
原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/45070393