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) Dates and Times strftime & strptime

benjamin siverly
benjamin siverly
3,430 Points

Task 1 no longer passing - works in workspaces

This runs on workspaces but says Task 1 no longer passes when using the cade challenge grader. Can someone tell me what is going on?

timestrings.py
import datetime


time_format = '%m %d %Y, %H:%M'
date = datetime.datetime.now()
the_string = "1 01 2020, 18:30"

def to_string(date):
    the_solution = date.strftime(time_format)
    print(the_solution)


def from_string(the_string, time_format):
    the_problem = datetime.datetime.strptime(the_string, time_format)
    print(the_problem)


to_string(date)
from_string(the_string, time_format)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You need to return the values, not print() it. The print works in Workspaces because, well, it'll happily print things out. But by not using return, your functions aren't actually giving back any information.