What is wrong with my code?


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

This is what I get as an error :

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


#2

Hi here

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

This part '%s/%s/%s''%s:%s:%s' there is'' between the last %s and the first %s: so try it like that

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

#3

Thank you for replying, I did exactly what you said but it keeps saying my code looks off :confused:


#4

Can you post your new code and the error you get.


#5

I did both this :

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

and this :

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

the error :

Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: invalid syntax (python, line 4)


#6

Here

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

Its missing a . between now and day


#7

Oh wow.. I feel like an idiot ahah.
I thank you kind sir !


#8

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

still am getting error can some one resolve ?


#9

set the variable
now = datetime.now()

print it

print datetime.now()

and thats what i did


#10

A post was split to a new topic: Date and Time Grand Finale Error