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

Alexander Bilton
Alexander Bilton
1,982 Points

"Far_away" - Returning datetime.datetime.now() + timedelta

Hi guys,

I can't figure out what I am doing wrong here. I am suposed to write a function called "far_away" that takes one argument, a timedelta. Then i need to return datetime.datetime.now() + the timedelta.

I have tried several things, including defining the timedelta within the function, outside etc.

I hope you can help out.

Alexander

far_away.py
import datetime

def far_away(t_delta):
    t_delta = datetime.timedelta(hours=5)
    return datetime.datetime.now()+t_delta

1 Answer

Hi there.

As we know, the code challenges are very specific in the results they expect returned. That said, it seems like the problem you had was that you defined the timedelta that was to be input. You essentially were supposed to let the timedelta be whatever was called into the far_away function, so the below passes.

import datetime

def far_away(t_delta):
    return datetime.datetime.now() + t_delta
Alexander Bilton
Alexander Bilton
1,982 Points

Hi Sean,

Thanks for your reply. Seems strange, since it hasn't got any clue whether my passing actually is a timedelta? Anyways, it worked.

Thx