Python Dates and Times in Python Let's Build a Timed Quiz App Harder Time Machine

Alex Golden
Alex Golden
4,098 Points

Harder 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?

time_machine.py
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?
Eldin Guzin
Eldin Guzin
2,504 Points

those comments got me lmao

1 Answer

Steven Parker
Steven Parker
202,109 Points

You 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
Alex Golden
4,098 Points

Steven! Thank you for a speedy reply.