Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,862 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.