#!usr/bin/env python
#-*- coding=utf-8 -*-
from datetime import *
import calendar
class BlackFriday(object):
def __init__(self,year):
self.year=year
def display(self):
print 'The black Fridays of year %s is(%s-1-1 is %s):' % (self.year,self.year,datetime(self.year,1,1).strftime('%A'))
L=[]
for i in range(12):
if 4==calendar.weekday(self.year,i+1,13):
L.append(str(self.year)+'/'+str(i+1)+'/13')
# print '%s' % datetime(self.year,i+1,13).strftime('%A')
if None==L:
print "There's none of Black Friday in year %s" % self.year
else:
print L
year=raw_input('请输入年份(1970~9999):')
BlackFriday(int(year)).display()
保存为blackfriday.py后运行结果如下:
[root@localhost zhidao]# python blackfriday.py
请输入年份(1970~9999):1970
The black Fridays of year 1970 is(1970-1-1 is Thursday):
['1970/2/13', '1970/3/13', '1970/11/13']
[root@localhost zhidao]# python blackfriday.py
请输入年份(1970~9999):1986
The black Fridays of year 1986 is(1986-1-1 is Wednesday):
['1986/6/13']
[root@localhost zhidao]#
温馨提示:答案为网友推荐,仅供参考