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

time_machine challenge. Try Again. What is the expected datetime result supposed to look like?

I have spent a lot of time troubleshooting a working solution, however "try again" is not giving me enough indication of what i am doing wrong. Below are my workspace tests to discover if my code is broken.

import datetime


def delorean(hrs):
    starter = datetime.datetime(2015, 10, 21, 16, 29)
    delta_hrs = datetime.timedelta(hours=hrs)
    print("datetime for hrs={} is {}".format(hrs, starter + delta_hrs))
    return starter + delta_hrs

delorean(5)
delorean(100)
delorean(1000)
delorean(10000)

my workspace console results for the above.

datetime for hrs=5 is 2015-10-21 21:29:00
datetime for hrs=100 is 2015-10-25 20:29:00
datetime for hrs=1000 is 2015-12-02 08:29:00
datetime for hrs=10000 is 2016-12-11 08:29:00

Any ideas where I could be going wrong? What am I missing out of the instructions for this challenge? "Try Again" is not helping me understand what is wrong. Below is the Challenge Code I am trying to submit for the challenge.

time_machine.py
import datetime

def delorean(hrs):
    starter = datetime.datetime(2015, 10, 21, 16, 29)
    delta_hrs = datetime.timedelta(hours=hrs)
    return starter + delta_hrs

1 Answer

Alex Koumparos
Alex Koumparos
Python Web Development Techdegree Student 33,851 Points

Hi cb123,

starter is a variable that should exist outside your function.

Your function should start on the row below the declaration of the starter variable. As that variable has global scope, your function will still be able to access it.

Thanks. originally i had it that way, but while solving for other things in the code I broke the one thing i had correct.

"Try again" has become the bane of my existence.