from datetime import datetime,timedelta
import re
def which_date(start_date,time):
"""
This function takes as input a string depicting a date in YYYY/mm/dd
format and a string stating a time period in the form of "X day(s)" or
"Y week(s)". Output should be a string in form YYYY/mm/dd with the date
that is X days or Y weeks after the initial date.
""" # Replace this with your code!
if time.find('day') > 0:
day = time.split()
end_date = datetime.strptime(start_date, "%Y/%m/%d") + timedelta(days=int(day[0]))
else:
week = time.split( )
end_date = datetime.strptime(start_date, "%Y/%m/%d") + timedelta(weeks=int(week[0]))
return end_date.strftime("%Y/%m/%d") def test():
"""
Here are a few tests to check if your code is working correctly! This
function will be run when the Test Run button is selected. Additional
tests that are not part of this function will also be run when the Submit
Answer button is selected.
"""
assert which_date('2016/02/10','35 days') == '2016/03/16'
assert which_date('2016/12/21','3 weeks') == '2017/01/11'
assert which_date('2015/01/17','1 week') == '2015/01/24'
print("All tests completed.") if __name__ == "__main__":
test()

最新文章

  1. final阶段成员贡献分
  2. 【圣诞特献】Web 前端开发精华文章推荐【系列二十一】
  3. spring 初始化之后执行的方法
  4. 来聊聊apply和call
  5. CodeForces - 241E Flights 题解
  6. [ CodeVS冲杯之路 ] P1053
  7. JAVA四种线程池实例
  8. 【CSS3】Advanced6:Attribute Selectors
  9. Enter键提交表单
  10. 如何测试私有 Private/Internal 方法
  11. 致网友Wonderfei的一封信(怎样选择自己主动化框架的几点拙见)
  12. 什么是Css Hack?ie6,7,8的hack分别是什么?
  13. Python推荐算法学习1
  14. 接口-以PHP为例
  15. springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo
  16. MVCC(Multi-version Cocurrent Control)多版本并发控制协议
  17. virtualbox+vagrant学习-1-环境安装及vagrantfile的简单配置-Mac系统
  18. BZOJ4732. [清华集训2016]数据交互(树链剖分+线段树+multiset)
  19. bzoj千题计划142:bzoj3144: [Hnoi2013]切糕
  20. C++面向对象编程,继承,数据抽象,动态绑定

热门文章

  1. day55——django引入、小型django(socket包装的服务器)
  2. emmet html缩写
  3. 精通Spring Boot
  4. C# 8.0 中开启默认接口实现
  5. Function.prototype.apply.call 理解分析
  6. vue中keep-alive,include的指定页面缓存问题
  7. 利用chocolatey软件包管理工具安装yarn,比npm更快更稳定
  8. PHP提示 Notice: Undefined variable
  9. H3C IEEE 802.11无线局域网工作组
  10. Docker-compose(创建容器)