Lab 3

Lab Description

For this lab I had to print the date (month,day and year), as well as the time (hour,minute and seconds). To do this I had to import datetime. After I imported datetime, I set it to the variable “now”. I was then able to print the month date and year. The date at the time was 10/9/2013. To take each separately and combine them, I took each individual one and assigned them to a variable as you can see in the script down below. For the time this was more challenging. Since the time is constantly changing and the program wanted the exact time, I had to create a string for each one and add them together. For the final piece which was to combine them both, I took each one and assigned them to a variable and then added them both together.

Script

import datetime
now = datetime.now()
print now
print now.month
print now.day
print now.year
x = "10/"
y = "9/"
z = "2013"
print x + y + z
print now.hour
print now.minute
print now.second
semicol = (":")
print str(now.hour) + str(semicol) + str(now.minute) + str(semicol)+ str( now.second)
date = str(x + y + z)
time = str(now.hour) + str(semicol) + str(now.minute) + str(semicol)+ str( now.second)
space = " "
print date + str(space) + time

Screenshot

code

Leave a Reply

Your email address will not be published. Required fields are marked *