Date and Time Please Help


#1

Question
Print the date and time together in the form: mm/dd/yyyy hh:mm:ss.

To start, change the format string to the left of the % operator.

Ensure that it has 6 %s placeholders.
Put slashes and colons and a space between the placeholders so that they fit the format above.

Then, change the variables in the parentheses to the right of the % operator.

Place the variables so that now.month, now.day, now.year are before now.hour, now.minute, now.second. Make sure that there is a ( before the six and a ) after them.

What is wrong with the answer?

Answer:
from datetime import datetime
now = datetime.now()

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


#2

Your code is correct you are simply not putting it in the right format.
It's asking you to put the date and time next to each other rather than on top of each other.

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

If this helped you please mark my reply as the solution :slight_smile:


#3

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