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 trial

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

What's missing from this simple time_machine challenge?

Is the time variable starter supposed to be on the inside of the delorean function? To be before, I subtracted the hours passed in to decrease the starter time. When I try it in my workspace, the code runs as expected.

time_machine.py
import datetime

def delorean(before_start):
    starter = datetime.datetime(2015, 10, 21, 16, 29)
    print(starter)
    jumped = starter - datetime.timedelta(hours=before_start)
    print(jumped)
    return jumped


jumped_started = delorean(4)
print(jumped_started)

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29) # move this out of function
def delorean(before_start):
    print(starter)
    jumped = starter + datetime.timedelta(hours=before_start) # + not -
    print(jumped) 
    return jumped


jumped_started = delorean(4)
print(jumped_started)

Thank you Clayton. I had used the "-" instead of the "+" because I thought the question asked for before the start time.