我正在学习Python 3基础知识,这是一个作业问题,我以为这很简单,但我肯定会遗漏它。我一直在寻找解决方案,似乎找不到任何不是从今天开始的日期,而是任何给定日期的东西。
此练习使用的是“导入日期时间”,并从给定日期起90天返回新日期。
我的代码是这样:
def add90Days(year, month, day):
given_date = datetime.date(year, month, day)
new_date = given_date + datetime.timedelta(days=90)
return new_date
错误是这样:
TypeError: add90Days() missing 2 required positional arguments: 'month' and 'day'
Process finished with exit code 1
OR
def add90Days(date):
given_date = datetime.date(date)
new_date = given_date + datetime.timedelta(days=90)
return new_date
出现此错误:
TypeError:需要一个整数(获取类型为datetime.date)
以退出代码1完成的过程
您没有将正确的参数传递给函数。试试add90days(2019, 9, 30)