Date and Time Grand Finale


#1

This is my code
from datetime import datetime
now = datetime.now()

print ('%s/%s/%s %s:%s:%s') % (now.month, now.day, now.year, now.hour, now.minute, now.second)

This is the display
4/28/2017 22:26:36
None

This is the message

Oops, try again. Your printed date and time do not seem to be in the right format: mm/dd/yyyy hh:mm:ss

But clearly they are correct so I do not know what to do. Suggestions welcome?


#3

It tells you to do that in the instructions "Make sure that there is a ( before the six and a ) after them" but to check I tried the code without the () and it still gives the same result. The code runs, the result is correct but the same error message appears.


#4

Did you refresh the page? Also, can you put your code in preformatted text so I can see if there's anything else wrong?


#5

Yes tried that as well same result


#6

Can you put your code in preformatted text, like this:


I hope you can see what I'm pointing to. is the </> logo
Or you can take a screen shot of your code if that's easier :slight_smile:


#7

This is valid Python, but the closing parens on the string should be at the very end.

print ( " ... " % ( ... ) )
        -----------------

Everything inside the outer parens.

In Python 3, print is a function, so the parens are mandatory. They are optional in Python 2, meaning they are ignored.

print " ... " % ( ... )

#8

from datetime import datetime
now = datetime.now()

print ('%s/%s/%s  %s:%s:%s') % (now.month, now.day, now.year, now.hour, now.minute, now.second)

#9

See the post above yours for clarification.


#10

Thanks. I tried that option as well. Still got the same result. The code runs, the printout is correct but the same error message!!!!


#11

Which course are you on? It doesn't look finished.


#12

Date and time Grand Finale


#14

read what @mtf said. It should help. :slight_smile:


#15

print ('%s/%s/%s  %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second))

I had tried that as well with the same result. 4/28/2017 23:15:46
None

But same error message


#16

The SCT is expecting only one space here.


#17

Great thanks that was it


#18

Now is ok many thanks I thought there was only one space there but clearly two :slight_smile:


#20

Ah! Ok I have now done that as well


#22