-2

I'm learning the Python 3 basics and this is a homework question, I thought it was simple but I'm definitely missing it. I have searched for solutions and can't seem to find anything that DOESN't start with today's date but just any given date.

This exercise is utilizing 'import datetime' and returns the new date 90 days from a given date.

My code is this:

def add90Days(year, month, day):
     given_date = datetime.date(year, month, day)
     new_date = given_date + datetime.timedelta(days=90)
     return new_date

The error is this:

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

with this error:

TypeError: an integer is required (got type datetime.date)

Process finished with exit code 1

Edit:

import datetime

Complete this function to add ninety days to the given date, return the new date

 def add90Days(date):
     given_date = datetime.date(date)
     new_date = given_date + datetime.timedelta(days=90)
     return new_date

expected output: 2018-12-30

print(add90Days(datetime.date(2018, 10, 1)))

expected output: 2015-05-12

print(add90Days(datetime.date(2015, 2, 11)))

The calls are prewritten in the exercise as the expected output. I wrote the function but the "def add90days(date)" was prewritten as a starting point for the exercise

s11m00ne
  • 3
  • 4
  • 2
    Please include full tracebacks. Also show how you're calling the functions – Jab Oct 01 '19 at 15:50
  • 1
    This is entirely about what you are sending to that function. – Daniel Roseman Oct 01 '19 at 15:50
  • Traceback (most recent call last): File "C:/Users/rxnrp/PycharmProjects/HelloPython/hellopython.py", line 15, in print(add90Days(datetime.date(2018, 10, 1))) File "C:/Users/rxnrp/PycharmProjects/HelloPython/hellopython.py", line 6, in add90Days given_date = datetime.date(date) TypeError: an integer is required (got type datetime.date) – s11m00ne Oct 01 '19 at 15:53
  • @s11m00ne Please edit it into the question body; comments can be cleaned up at any time. Also be sure to show how your function is being called. – glibdud Oct 01 '19 at 15:55
  • I'll edit into the question body, thanks. – s11m00ne Oct 01 '19 at 15:59

2 Answers2

1

You didn't pass the correct arguments to your function. Try add90days(2019, 9, 30)

blue_note
  • 27,712
  • 9
  • 72
  • 90
0

I know this is necro post and late but I had to answer. The only thing you need in your function is below.

new_date = date + datetime.timedelta(days=90)
return new_date
TRoberts
  • 11
  • 2