Module_7
- Angela Porcelli
- Feb 27, 2021
- 2 min read
Updated: Mar 1, 2021
Original data: Try the code below and revise it to current time.
importsys
forlineinsys.stdin:
data=line.strip().split("\t")
iflen(data) ==6:
date, time, store, item, cost, payment=data
print"{0}\t{1}".format(item, cost)
I didn't understand this code with the question. I assume the request is to return the current time with six unique data features on separate lines. To achieve this I used current_time as a variable for the Datetime module's datetime class. I then had 6 unique aspects for date and time return on separate lines.

2. Add the timedelta to the datetime and subtract 60 second and added 2 year . For each condition, state the code and output.
For this problem, I imported datetime and timedelta from the Datetime module. Then I assigned the method .today() to the class datetime which was assigned to variable d. I assigned a parameter of 60 seconds to the timedelta class indicating it should be subtracted by using the - symbol. Next, I assigned a parameter of 2 hours to the timedelta class indicating it should be added by using the + symbol. Last, I used a string format to add the hours and subtract the minutes from the return of datetime.today() and printed the result.

3. Create a timedelta object representing 100 days, 10 hours, and 13 minutes.
Since an object is an instance of a Class, the first thing that needs to be done is to define a Class. I defined PA as my Class. The next thing that needs to be done is to declare or instantiate objects to the Class. For this problem, the objects are provided in the question: days, hours, and minutes. Lastly, attributes need to be assigned to the objects. Again, using the given information, 100 is attributed to days, 10 is attributed to hours, and 13 is attributed to minutes.

4. Write a function that takes two arguments (feet and inches) with this time object.
For this question, I used the distance of a 5K course in feet and inches and returned those values with the current date and time using datetime.now(). I passed the feet and inches arguments to the function LQ. First, I defined the function LQ, then I passed the arguments using * since I had multiple arguments to assign to the function. Then I added the Datetime module to the print code in order for the date to be included with the output.



Comments