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 Time Tango

Andrei Oprescu
Andrei Oprescu
9,547 Points

How can I complete this challenge?

Hi! I have come across this question on a challenge that looks like this:

Write a function named time_tango that takes a date and a time. It should combine them into a datetime and return it.

I have created a code that looks like the one at the bottom of the page.

Can you please tell me what I have done wrong and how I can fix it?

Thanks!

Andrei

combo.py
import datetime

def time_tango(date, time):
    datetime1 = date.combine(time)
    return datetime.datetime.strptime('%m/%d %H:%M', datetime1)

1 Answer

Steven Parker
Steven Parker
231,248 Points

When the instructions say, "It should combine them into a datetime and return it" they mean to return the datetime itself. No need to convert it into a string.

But also you're not calling the "combine" function correctly. Take a look at the documentation page for the correct syntax.

Andrei Oprescu
Andrei Oprescu
9,547 Points

Thanks! I read the question wrong ;).

Andrei