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 trialAlex Golden
4,098 PointsHarder Time Machine is Harder
I keep getting an error: Bummer: 'new_time_str' is an invalid keyword argument for this function
I tried running the code in the workspace and it looks like datetime doesn't want me to input the new_time_str at all. Is there a way to get datetime to take this argument or am I relegated to a collection of "if" statements?
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29)
def time_machine(num, time_str):
# First, purage the EVIL LETTER S from the input string so that datetime doesn't herniate.
new_time_str = time_str.replace("s", "")
# Then return the original time PLUS the change in time with the new s-less string as the argument to be changed
# using the integer input 'num'
return starter + datetime.timedelta(new_time_str = num)
# get an error....
# Get and error?
1 Answer
Steven Parker
231,236 PointsYou seem to have gotten off track a bit. Here's a few hints:
- the keyword in an keyword/value argument cannot be a variable
- you can build kwargs from a dictionary using the "splat" operator (but there are simpler approaches)
- the letter "s" is a legitimate part of the keywords for arguments for "timedelta"
- you need to handle "years" but "timedelta" doesn't do them itself (there originally was a comment about this)
Alex Golden
4,098 PointsSteven! Thank you for a speedy reply.
Eldin Guzin
6,010 PointsEldin Guzin
6,010 Pointsthose comments got me lmao