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()

完成下方的 which_date() 函数,并返回某一起始时间后特定一段时间的日期的更多相关文章

  1. sh_06_函数的返回值

    sh_06_函数的返回值 def sum_2_num(num1, num2): """对两个数字的求和""" result = num1 + ...

  2. Python函数01/函数的初识/函数的定义/函数调用/函数的返回值/函数的参数

    Python函数01/函数的初识/函数的定义/函数调用/函数的返回值/函数的参数 内容大纲 1.函数的初识 2.函数的定义 3.函数的调用 4.函数的返回值 5.函数的参数 1.函数初识 # def ...

  3. 『无为则无心』Python函数 — 27、Python函数的返回值

    目录 1.返回值概念 2.return关键字的作用 3.返回值可以返回的数据类型 4.函数如何返回多个值 5.fn5 和 fn5()的区别 6.总结: 1.返回值概念 例如:我们去超市购物,比如买饮料 ...

  4. Entity Framework 6 Recipes 2nd Edition(11-6)译 -> 从一个”模型定义”函数里返回一个复杂类型

    11-6.从一个”模型定义”函数里返回一个复杂类型 问题 想要从一个”模型定义”函数返回一个复杂类型 解决方案 假设我们有一个病人(patient)和他们访客(visit)的模型,如 Figure 1 ...

  5. 测试函数用Return 返回值和用函数名返回值的区别

    '*************************************************************************'**模 块 名:工程1 - Form1'**说   ...

  6. Shell入门教程:Shell函数的返回值

    shell函数返回值一般有3种方式: 1.return语句(默认的返回值) shell函数的返回值可以和其他语言的返回值一样,通过return语句返回. 比如: #!/bin/bash functio ...

  7. UNIX 系统调用函数errno返回值搜集(in updating )

    当Unix系统级函数遇到错误时,它们会典型地返回-1,并设置全局整数变量errno来表示什么出错了 阅读redis源码的时候,发现如果对系统级函数出错时的errno比较熟悉,写起程序来会游刃有余不少. ...

  8. GDB 修改当前判断函数的返回值(即修改寄存器的值)的方法

    工作中遇到的问题: 在GDB调试时要进入下边该判断后边的函数,而m_EtherDecode.Chk_MakeSure_IP_Pkt(pPacket,dwPacketLen)的返回值是false,所以需 ...

  9. 面试题-->写一个函数,返回一个数组中所有元素被第一个元素除的结果

    package com.rui.test; import java.util.Random; /** * @author poseidon * @version 1.0 * @date:2015年10 ...

随机推荐

  1. 熟悉javaEE主流框架Spring boot,Spring Cloud,Mybatis,了解Servlet,JDBC

    什么是Tomcat 阿帕奇提供的小型服务器软件,支持servet和jsp规范 lib包:存放jar包 WabApp:发布项目的目录 work:jsp编译生成.class的目录 LOgs:存放日志文件 ...

  2. lambd

    匿名函数 1.匿名函数格式 void test01() { []() { cout << "hello world" << endl; }(); } 2使用 ...

  3. modbus汇总

    ModBus协议简介及移植到STM32单片机 https://blog.csdn.net/silent123go/article/details/92440091 Modbus测试工具ModbusPo ...

  4. redis源码分析(二)-rio(读写抽象层)

    Redis io抽象层 Redis中涉及到多种io,如socket与file,为了统一对它们的操作,redis设计了一个抽象层,即rio,使用rio可以实现将数据写入到不同的底层io,但是接口相同.r ...

  5. 你也可以写个聊天程序 - C# Socket学习1

    原文:你也可以写个聊天程序 - C# Socket学习1 简述 我们做软件工作的虽然每天都离不开网络,可网络协议细节却不是每个人都会接触和深入了解.我今天就来和大家一起学习下Socket,并写一个简单 ...

  6. sping boot/cloud配置文件 on 读取为true

    sping boot/cloud配置文件 on 读取为true 原文地址:https://blog.csdn.net/hb9176070/article/details/82749771 最近在写sp ...

  7. vxlan 协议

    vxlan 协议原理简介 1. vxlan 简介 VXLAN 全称是 Virtual eXtensible Local Area Network,虚拟可扩展的局域网.它是一种 overlay 技术,通 ...

  8. Fiddler-修改请求的上行参数

    方法一:对所有的请求打断点 1.rules->automatic Breakpoints->Befor Requests 2.点击选择需要修改的请求 3.选择右侧请求区域的 Inspect ...

  9. 【转载】 C#中使用float.Parse方法将字符串转换为Float类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为单精度Float类型就是一个常见的类型转换操作,float.Parse方法是C#中专门用来将字符串转换为float类型的,f ...

  10. IDEA插件:search with bing、search with baidu

    //转载请注明出处:https://www.cnblogs.com/nreg/p/11267169.html 当项目出现错误时,经常需要复制错误信息粘贴到浏览器查询,但是手动复制再粘贴太麻烦了, 因此 ...