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 trialcb123
Courses Plus Student 9,858 Pointstime_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.
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
Python Development Techdegree Student 36,887 PointsHi 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.
cb123
Courses Plus Student 9,858 Pointscb123
Courses Plus Student 9,858 PointsThanks. 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.