Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) Dates and Times Far Away

Quiz: datetime + timedelta addition example not passing("Bummer...") but works in offline workspace

my code works in offline Python workspace but always produces "Bummer! try again!" in Quiz. I tried several different approaches that also work offline. I watched video again and re-read question. I can't figure out why it's not passing Quiz code: (all these code lines work):

import datetime

def far_away(td): return datatime.datetime.now() + datetime.timedelta(days=td)

return datatime.datetime.now() + datetime.timedelta(hours=td)

return datatime.datetime.now() + datetime.timedelta(td)

far_away.py
import datetime

def far_away(td):
  return datetime.datetime.now() + datetime.timedelta(days=td)

Yes this passed the quiz: import datetime

def far_away(td): return datetime.datetime.now() + td

But in PyCharm environment this code errors because it can't add datetime and int() types.

Anyway, thanks for your help. I never would have got it.

You didn't give an example of how you were calling the far_away function when testing on your own.

I suspect you were doing something like this: far_away(5) where you're just passing in an int.

This is not what the challenge is describing though. It's saying that it will pass a timedelta object as the argument, not a simple int.

If you pass an int, then yes, you would need to create a timedelta object out of that.

I think that you're probably not testing your code under the same requirements as the code challenge is testing your code.

1 Answer

Hi ross,

The argument that is passed in is already a timedelta object. You don't need to create another one.

You only need to add the argument passed in to datetime.datetime.now()