Working with Datetime and Timedelta in Python
This week’s assignment focused on using the datetime and timedelta modules in Python. I practiced working with time-based objects, performing calculations, and combining date/time data with custom functions. Code Procedure: Simulated reading transaction data and displayed the item/cost with the current time using datetime.now() Used timedelta to subtract 60 seconds and add 2 years (730 days) to the current time. Created a timedelta object representing 100 days, 10 hours, and 13 minutes and printed the result. Wrote a function that takes 2 arguments (feet and inches) and prints them along with the current datetime. These exercises helped me better understand how Python handles time-based data and how to apply that to real-world scenarios. Code: from datetime import datetime, timedelta # 1. Display current time with item & cost sample_data = "2025-06-29\t11:23:00\tPublix\tMilk\t3.25\tCredit" data = sample_data.strip().split("\t") if len(data) == 6: ...