Python Challenge[15]

[Level 15]


Title: whom?

源码中有两处注释:

  1. he ain't the youngest, he is the second
  2. todo: buy flowers for tomorrow

图片中年份被划掉了。如果能注意到右下角显示的二月有29天,那么思路就清晰了。还应注意到日期对应的星期。

import datetime
year = [i for i in range(1006,1997,10)]
for i in year:
  if (i%100==0 and i%4==0) or (i%4==0 and i%100!=0):
    date = datetime.date(i,1,26)
    if date.weekday()==0:
      print(i)

五个年份,提示又是第二年轻,所以是1756。又是tomorrow,所以是1756年1月27日。搜索可知道莫扎特(Mozart)的生日正是这个,[Level 16]

小结

  1. date.weekday()将星期作为数字返回,星期一为0,星期天为6。date.isoweekday()功能相同,但是星期一为1,星期天为7。

Python Challenge Wiki

判断闰年可以更简洁。calendar.isleap(year)直接判断是否闰年。

More

你可能感兴趣的:(Python Challenge[15])