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

Far Away timedelta Challenge

Hey, Can someone look into my code and see what I am doing wrong to tackle this assignment?

far_away.py
import datetime
now = datetime.datetime.now()
far_away = datetime.timedelta( hours=0)
datetime = now + far_away

2 Answers

Steven Parker
Steven Parker
231,275 Points

The instructions say, "Write a function called far_away that takes one argument, a timedelta. Add that timedelta to datetime.datetime.now() and return the resulting datetime object."

So here are some hints based on what you have so far:

  • to create a function, use the "def" keyword
  • the function definition must include an argument (you can pick the name)
  • the argument will provide the timedelta so you won't need to construct a new one
  • be sure to return the calculated date
  • remember that the body of a function must be indented more than the "def" line

Thank you, Steven, this was helpful. Done

Thank yo pierreilyamukuru I was able to get the datetime importa which I was missing in my process, you're the best; however, may I suggest the following answer which worked for me?

```import datetime

def far_away(timedelta) now = datetime.datetime.now() retiurn now + timedelta

I hope this helps