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 trialDante Vittorelli
2,301 PointsGetting an error stating that the correct answer is wrong.
For some reason I am getting the error " Bummer! to_string
returned the wrong string. Returned '24 September 2012'."
I don't understand why because the challenge is asking for exactly that date, yet it's not passing.
Would anyone know why this is happening?
import datetime
def to_string(x):
x = datetime.datetime.now()
x = x.replace(year = 2012, month = 9, day = 24)
z = x.strftime('%d %B %Y')
return z
[MOD: added ```python markdown formatting -cf]
Dante Vittorelli
2,301 PointsSorry, I clicked the checkbox that says "attach code to post" but I guess it didn't attach it.
import datetime
def to_string(x):
x = datetime.datetime.now()
x = x.replace(year = 2012, month = 9, day = 24)
z = x.strftime('%d %B %Y')
return z
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe error is your are overwriting the argument x
with your own value.
import datetime
def to_string(x):
#x = datetime.datetime.now()
#x = x.replace(year = 2012, month = 9, day = 24)
z = x.strftime('%d %B %Y')
return z
This should work for Task 1
Dante Vittorelli
2,301 PointsOh wow... my answer makes no sense now that I get it haha. Thank you for your help.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Pointsplease post your code! Thx.