Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python 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()