Why doesn’t it accept my answer if I put spaces around the slashes?



Why doesn’t it accept my answer if I put spaces around the slashes?


For any exercise on Codecademy, your code is checked over by tests running in the background when you press Run. If the instructions ask for a specific output, variable name, or value, that is exactly what you must type.
Computer’s aren’t able to interpret what you meant to type, so we have to use exactly what is being checked for, otherwise it’ll be counted wrong.
In this exercise, it asks for us to display the date as mm/dd/yyyy, without any spacing anywhere. So that’s exactly how we should print it, and including spaces will throw a convenient error message:
It looks like there are spaces surrounding the slashes.

FAQ: Learn Python - Date and Time - Hot Date

it did work

from datetime import datetime
now = datetime.now()
print '%02d / %02d / %04d' %(now.day, now.month, now.year)

my Result
08 / 09 / 2018


Did it work in the lesson, though? What you have fashioned is print output, not a date string. Standard date formats have no spaces in them. In order for that to be accepted in the lesson, the spaces must be removed.


take a look at my screenshot

i was wondering too sir


I run it for hour:minute:second, it run and displayed the result but again displayed

It looks like there are spaces surrounding the colons. Remember to use + for string concatenation

Don’t whether its because i run it inside the practicing environment?
Sir, i really need clarification on this one.


It is the lesson environment that is reporting that error which means it doesn’t match the expectations. The lesson checker is very limited in scope and does not have a range of expectations. More likely, there is one expected pattern to match against, and that’s it. Deviation from that pattern, however valid, will result in an error.

We’re writing lesson code, not real world production code. For best results follow the instructions to the letter.


Thanks you very much sir.


Does it matter what letter you use after the %02 ? I tried d and I and they worked but other like f and a didn’t. What is the importance of the letters after the %02/%04s?


Yes, it must be a letter that the interpreter recognizes.

d => digit
i => integer (same as above)
f => float
s => string
r => representation (a list, tuple, set, dictionary)

%04s will pad the left side of a string with spaces up to a maximum output length of 4. If the string is 4 or more characters long there will be no pad.

>>> print ("%04s" % 'a')
>>> print ("%04s" % 'abcde')
>>> print ("%04d" % 1)
>>> print ("%4.2f" % 1.1)

Note how it pads a number with 0’s. Note also how padding is ignored on floats.


The above has both old and new examples for comparison. The new format method may not work in Python 2. There is a way to include it but I’ve forgotten and will have to research that again.