【原创】pythonchalleng——第15题
第十五题的网址:http://www.pythonchallenge.com/pc/return/uzi.html,下面是该题目的截图,特此留念。

- 年份是1**6年,那么范围就是1006-1996年。
- 日期为1月26日,星期一。
- 右下角包含了二月的信息,从这可以看出,这一年是闰年
- he ain't the youngest, he is the second。
- buy flowers for tomorrow 通过提示信息,我们整理下思路:1006-1996年间,哪些年的1月26日是星期一,并且这一年是闰年。OK,我们看看在写代码的时候我们需要什么。对,就是操作日期的库——calendar和datetime。下面上代码:
# coding:utf-8
__author__ = 'hengha'
import calendar,datetimedef dealDate(start, end, month, day, weekday):
result=[]
for i in range(start,end,10):
d=datetime.date(i, month, day)
if d.isoweekday()==weekday and calendar.isleap(i):result+=[d.year]
return resultif __name__ == '__main__':
res=dealDate(1006, 1996, 1, 26, 1)
newdate=datetime.date(res[-2],1,27)
print newdate# the birthday of Mozart
res中保存的就是满足前三条要求的所有年份,由于"he ain't the youngest, he is the second",所以我们利用res[-2]取出倒数第二个年份,那就是1756。再根据最后一条提示,我们得到的日期就是1756-1-27。这是什么日子呢?百度一下,得到答案:Mozart的生日。好了,试一试http://www.pythonchallenge.com/pc/return/Mozart.html,得到的结果居然是网页不存在……把M小写试一试,嗯,这就对了。http://www.pythonchallenge.com/pc/return/mozart.html。OK,顺利进入第16题。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
