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 trialdarcyprice
4,442 PointsI believe that I have solved the Challenge (Task 2), but I get a message saying "Task 1 is no longer passing".
I completed Task 1 with the included code and didn't adjust it in Task 2.
I am not sure why Task 1 would now not be passing, unless I am misunderstanding the question, and Task 2 requires us to edit def to_string?
What am I doing wrong? Any help would be much appreciated!
Thanks all ! :)
# to_string(datetime_object) => "24 September 2012"
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
import datetime
def to_string(dt):
return dt.strftime('%d %B %Y')
def from_string(str_dt, str_strftime)
"""
Accept a date as a string (str_dt) and an strftime-compatible format string (str_strftime)
and return a datetime created from time
>>> from_string('09 March 2018', '%d %B %Y')
datetime.datetime(2018, 3, 9, 0, 0, 0, 0, 0)
"""
return datetime.datetime.strftime(str_dt, str_strftime)
2 Answers
Steven Parker
231,269 PointsAny syntax error will invalidate the entire program and cause the re-validations to fail.
In this case it is caused by a missing colon at the end of the "def" line of the new function.
The function also has "strftime" instead of "strptime".
darcyprice
4,442 PointsAhhhh what a silly mistake,
Thank you Steven, much appreciative! :)
I review the difference between strftime and strptime now too