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 trialSergio Lopez
13,088 Pointsinvalid keyword argument
If this were pseudocode, it would work, but I get the 'invalid keyword argument" inside the timedelta function when I try to pass the string variable as an argument. How do you pass the string argument to the timedelta function?
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29)
integer = 5
string = "hours"
def time_machine(integer, string):
return starter + datetime.timedelta(string = integer)
# 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)
2 Answers
Tree Casiano
16,436 PointsHi Sergio, I built the code for this challenge out of a series of if-else statements. Here's the first snippet of code from my function. Using the name of the variable in your case "string," throws a keyword error because the function requires one of the datetime keywords such as hours, days, or minutes rather than a variable that stores the value for the particular number of hours, days, etc.
def time_machine(integer, string1):
if string1 == 'hours':
return starter + datetime.timedelta(hours=integer)
Kenneth Love
Treehouse Guest TeacherIf this were pseudocode, it would work
Well, yeah :) that's the beauty of pseudocode, it always does what you expect.
Tree Casiano's suggestion is a good one.