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 trialBLESSING TASHINGA GURENJE
5,793 Pointshelp here please
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.
def far_away():
import datetime
now = datetime.datetime.now()
return datetime
5 Answers
Joshua Hoy
4,887 PointsRemember - Imports like to go up top so that's where I begin..even if they don't HAVE to, that's where this course has been placing them.
If you start by importing the datetime at the top and begin you will have a better chance. What I did was simply define the function far_away, inserted the argument 'timedelta' and closed ':'.
I then created a variable to hold the argument + the datetime.datetime.now()
I then simply returned that variable.
Pedro Cabral
33,586 PointsYour function should take one argument and it takes 0. You are importing the datetime module, use it to build an object with the current local time and return the datetime module at the end. You are very far off from what's being asked. I suggest you take a step back and master the basics before delving into the datetime library otherwise I think you'll be even more confused.
Anupam Kumar
3,795 Pointsimport datetime def far_away(timedelta): now = datetime.datetime.now()+datetime.timedelta(timedelta) return now
Why is the problem with this code??
Pedro Cabral
33,586 PointsAlmost there. You don't need to initialize/construct the timedelta because you already receive it via the function argument. You should use it straight away as is.
Anupam Kumar
3,795 PointsAny solution or help on this, Does anyone here to help >>
diginoma
Courses Plus Student 8,009 Pointsimport datetime
def far_away():
now = datetime.datetime.now()
newnow = now + datetime.timedelta()
return newnow
Why? I rewatched the videos several times, I ran similar code in pycharm, just...why??