Stuck on Python


#1



from datetime import datetime
now = datetime.now()

print '%s:%s:%s:%s:%s:%s' % (mm/dd/yyy hh:mm:ss)


https://www.codecademy.com/courses/python-beginner-en-zFPOx/0/6?curriculum_id=4f89dab3d788890003000096#


File "python", line 4
print '%s:%s:%s:%s:%s:%s' % (mm/dd/yyy hh:mm:ss)
^
SyntaxError: invalid syntax


Replace this line with your code.


#2

This is the invalid code. The argument list should be comma separated. Write the slashes and colons in the string segment.


#3

Did you mean something like this? Thanks.

from datetime import datetime
now = datetime.now()

print '%s:%s:%s:%s:%s:%s' % (mm,dd,yyyy,hh,mm,ss)

Traceback (most recent call last):
File "python", line 4, in
NameError: name 'mm' is not defined


#4

Sort of. The instructions ask us to format as,

"mm/dd/yyyy hh:mm:ss"

recall that now is a Date object with attributes:

now.month, now.day, now year, now.hour, now.minute, now.seconds

#5

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.seconds)

It still returns invalid syntax :frowning:


#6

Note where the slashes are written, and where the colons are written. Pay special attention to the space character between date and time. It shouldn't matter, but try using "..." (double quotes) on the string portion.


#7

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.seconds)


File "python", line 4
print "%s:%s:%s:%s:%s:%s" % (now.month, now.day, now year, now.hour, now.minute, now.seconds)
^
SyntaxError: invalid syntax


#8

Typo... seconds should be second.

You still do not have the correct string.

"%s/%s/%s %s:%s:%s"

#9

Solved :slight_smile: Thanks


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.