Does anyone see a bug in my code?


#1

from datetime import datetime
now = datetime.now()

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

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

Any ideas what went wrong ? Thank you in advance ...


#2

dont know why that 0 is there for starters.

join the prints into one.

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

You need it to be printed as mm/dd/yyyy hh:mm:ss on one line.


#3

benjnev thanks for response. I typed 0 on the start 'coz in preview didn't show up and I thought that's why I'm getting that error. It worked ok with that 0 however even with your suggestion still evaluates as wrong code.

I fixed the code the way you suggested:

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

but still error message keeps coming up:

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


#4

Ahh my apologies I did it like this

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

#5

I tried that as well. This is the way it comes out in preview: 1/21/201616:41:49
There's something wrong 'coz January supposed to go like 01 not just 1 (format MM)
And date and time is meant to be on one line together but not joined like it is. Gotta keep working on it.

Thank you for effort ! Appreciate it greatly.


#6

Try this

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


#7

This worked mate ! I understand it was meant to be on one line but didn't know how they meant it. Cheers !


#8

I did this but it gave me an error: print '%s/%s/%s %s:%s:%s:' % (now.year, now.month, now.day,now.hour,now.minute,now.second)