Date and time grand finale


#1



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


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

5/4/17 (7, 51, 53)
None

for the outcome to be 5/4/17 7:51:53

from datetime import datetime
now = datetime.now()

print '%s/%s/%s'% (5, 4, 17 ),  (7, 51, 53)

:


#2

from datetime import datetime
now = datetime.now()

print '%s/%s/%s'% (5, 4, 17 ), (7, 51, 53)

This is your code.

Key thing here to understand is ,You don't need to put date manually but you have to make computer to do it for you.

Meaning of first two lines..

from datetime import datetime

Python have datetime module and a datetime function in it.
this datetime function have methods that will give you current date,time etc.

Next line..

now = datetime.now()

what is datetime.now() ?
for the time being imagine it's like a file that have information about time and date .
if you print now like this..
print now
then it will print this...
2017-05-04 12:12:39.539310

you can see that this variable have lots of information inside it..

like year,current month,current day,current hour,minute,second etc.

One cool thing to know that we can access all these info separately..

like this.. we use our predefined variable now

now.year ---> will give -- > 2017
now.month -- > will give month -- > 5

same way you can access minute,hour,second.

in this line you have to formate your date and time...

print '%s/%s/%s'% (5, 4, 17 ), (7, 51, 53)

so instead of 5,4 or anything you have to use now variable and access all those details and ..
also note that there are 6 variables so you need six string identifier(%s)..like this

print '%s/%s/%s figure this out' % (now.year, ?,?,?,?,?)

? part - you have to figure out by your own!
there are 5 ?'s to find.


#3

sorrry I still dont really understand


#4

Can you expain it a little more simply


#5

I will refer you to revise previous exercise,this is the last exercise you're doing ? (of this section)


#6

yeah this is the last one


#7

If you revise last exercise then read what I wrote here ,then It may be more clear for you?
do that ,after doing that if it still does not make sense..I will explain :slight_smile:


#8

ok cool:+1: i will thanks


#9

ok I tried but I still didnt understand... sorry for bugging you too much btw.


#10

sorry meant to reply to you not myself


#11

from datetime import datetime
now = datetime.now()

Your first two lines are okay.

but...we have to make certain changes so it prompt right time and date..

print '%s/%s/%s'% (5, 4, 17 ), (7, 51, 53)

I'd give a hint..we have to prompt time like this..
2017/5/4 10:23:34


#12

oh ok i just remembered that i'll try that and get back to you


#13

OK i am sorry but I am completely lost on this last one it says to put them all on line instead of on different lines. This is th first one I have had real trouble with


#14

Can you show me your current code that throwing an error?


#15

print '%s/%s/%s''%s:%s:%s'% (5, 4, 17 7, 51, 53)


#16

oooooohhhhhhhh!!!! I just got it thank you so much I was reading what you said wrong thanks :+1: :+1: :+1:


#17

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


#18

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