找出输入年份的黑色星期五:
用法:
1 # -*-coding:utf-8-*- 2 3 # Python程序设计作业,找出黑色星期五 4 5 theYear = input ("Please input the year you want to konw : ") 6 7 theFirstDay = input ("What day is theFirstDay (1 , 2 , 3 , 4 , 5 , 6 , 7) : ") 8 9 day = 1 # 天数计数变量 10 11 bigMonth = [1 , 3 , 5 , 7 , 8 , 10 , 12] 12 smallMonth = [4 , 6 , 9 , 11] 13 14 if ((theYear % 4 == 0) and (theYear % 100 != 0)) or (theYear % 400 == 0) : 15 print u"这是闰年,二月份有29日" 16 17 for theMonth in range (1 , 13) : 18 if theMonth in bigMonth : 19 for theDay in range (1 , 32) : 20 if (theDay == 13) and (day % 7 == 5) : 21 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 22 day = day + 1 # 每轮一天即将天数计数变量加一 23 elif theMonth in smallMonth : 24 for theDay in range (1 , 31) : 25 if (theDay == 13) and (day % 7 == 5) : 26 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 27 day = day + 1 # 每轮一天即将天数计数变量加一 28 else : 29 for theDay in range (1 , 30) : 30 if (theDay == 13) and (day % 7 == 5) : 31 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 32 day = day + 1 # 每轮一天即将天数计数变量加一 33 34 else : 35 print u"这是平年,二月份有28日" 36 37 for theMonth in range (1 , 13) : 38 if theMonth in bigMonth : 39 for theDay in range (1 , 32) : 40 if (theDay == 13) and (day % 7 == 5) : 41 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 42 day = day + 1 # 每轮一天即将天数计数变量加一 43 elif theMonth in smallMonth : 44 for theDay in range (1 , 31) : 45 if (theDay == 13) and (day % 7 == 5) : 46 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 47 day = day + 1 # 每轮一天即将天数计数变量加一 48 else : 49 for theDay in range (1 , 29) : 50 if (theDay == 13) and (day % 7 == 5) : 51 print "The day is black Friday : %d / %d / %d " %(theYear , theMonth , theDay) 52 day = day + 1 # 每轮一天即将天数计数变量加一