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!
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
can someone please assist?
not sure how to do this any other way.
import datetime starter = datetime.datetime(2015, 10, 21, 16, 29) # Remember, you can't set "years" on a timedelta! # Consider a year to be 365 days. ## Example # time_machine(5, "minutes") => datetime(2015, 10, 21, 16, 34) def time_machine(i,st): st = str(st) td = datetime.timedelta(st=i) return starter + td
Hey Em Noble! So this one is tricky. It takes an int and a string. First, the
st won't need to be converted to a string because what is entered will already be a string. But the main issue lies with this line:
time_machine is being called with the following:
This function would be trying to create a timedelta with
"minutes"=4. This will not work because timedelta does not take a string. It takes
minutes as attributes. For example to do the one with hours, we would want it to say
datetime.timedelta(hours, 7) rather than
In order to do this we need some
elif statements that check if the string is equal to "minutes", "hours", "days", or "years", set the timedelta or
Remember that if "years" is entered in, it will need to get converted to years by multiplying by
Then you can return the starter + td.
Hopefully this helps!