Trouble with 6/6


#1

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)

Hey guys, anyone know what i am doing incorrectly here?


#2

no i am havng the same problem and kind find anything to help


#3

there's no period in between 'now' and 'year'


#4

I am in the same dilema here ....same code as you " print '%s/%s/%s' '%s:%s:%' % (now.month, now.day, now.year, now.hour, now.minute, now.second)
and geting this back :Traceback (most recent call last):
File "python", line 5, in
ValueError: incomplete format


#5

if still having problem sent whole code please


#6

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)
you need to place your hour and minute on line 6


#7

same problem my code looks like :
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)


#8

Same problem.
My code is:

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)

Nothing wrong in the interpreter but script message notices some wrong format


#9

Just figured this out.
from datetime import datetime
now = datetime.now()
print '11/04/1954 06:23:35'
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year,
now.hour, now.minute, now.second)

Add an apostrophe before and after the date.


#10

The code should look like this:
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)
print now.year
print now.month
print now.day


#11

your print function should be '%s/%s/%s %s:%s:%s' not ''%s/%s/%s/%s/%s/%s'
you also need a comma between year and hour

@dustin9xd
What is the point in the first print function?

@sygon
No need for the last 3 print functions

Correct 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)

#13

Thank you for your reply, worked perfectly!


#14

The more simple appears to be right

from datetime import datetime

now = datetime.now()

print now


#15

@betaace19113,

There is more than one bug, but they are easy to fix.

You have ...

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

The ValueError reported by the Python interpreter is due to your missing an s at the end of your format string. But once you fix that, you'll have this ...

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

The Python interpreter will now be happy, but then Codecademy will chime in with their own complaint. This is because you will output a date and time with no space in between. This results from your having composed your format string as two separate strings with whitespace in between, which will now appear as ...

'%s/%s/%s' '%s:%s:%s'

The Python interpreter handles that by concatenating the two strings. The space between them does not get included, so the result is equivalent to ...

'%s/%s/%s%s:%s:%s'

You need this, as your format string instead ...

'%s/%s/%s %s:%s:%s'

Once everything is fixed, we'll have this ...

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

Now the output will appear correctly, and everybody will have a happy day (and a happy hour, minute and second). :wink: