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 trialigor corrales
2,474 PointsProblem with timedelta, can anyone help me please ?
Probably I don't understand the exactly meaning of the exercixe ....because I get an object but I get an error.
import datetime
def far_away(number):
a = datetime.datetime.now() + datetime.timedelta(days=number)
return a
2 Answers
David Smith
10,577 PointsYou were almost there,
The quiz asked that the function take a time delta as an argument, not an int. All you have to do is;
import datetime
def far_away(number):
a = datetime.datetime.now() + number
return a
To help you understand I've modified some of the names
import datetime
# define the function and allow it to accept an argument. An argument is a variable that is used within a function.
def far_away(time_delta_argument):
# here we're setting a variable to the current time plus a timedelta
# a time delta is "datetime.timedelta(hours=7)"
datetime_datetime_now_plus_timedelta_argument = datetime.datetime.now() + time_delta_argument
# here we return the variable we set before
return datetime_datetime_now_plus_timedelta_argument
# this is not part of the challenge but I included it to help demonstrate how this function would be used
print(far_away(datetime.timedelta(hours=7)))
igor corrales
2,474 PointsThanks a lot for the explanation !!!
David Smith
10,577 PointsYou're welcome Igor, we've all been there :)