Complete the code to create a timedelta of 5 days.
from datetime import timedelta five_days = timedelta([1]=5) print(five_days)
The timedelta function uses the days parameter to represent a duration of days.
Complete the code to calculate the date 10 days after January 1, 2024.
from datetime import datetime, timedelta start_date = datetime(2024, 1, 1) new_date = start_date + timedelta([1]=10) print(new_date.strftime('%Y-%m-%d'))
Adding a timedelta with days=10 to the start date moves the date 10 days forward.
Fix the error in the code to subtract 3 hours from a datetime object.
from datetime import datetime, timedelta now = datetime(2024, 6, 15, 12, 0) new_time = now - timedelta([1]=3) print(new_time.strftime('%H:%M'))
The correct parameter for hours in timedelta is hours (plural), not hour.
Fill both blanks to create a dictionary with words as keys and their lengths if length is greater than 4.
words = ['apple', 'bat', 'grape', 'kiwi'] lengths = {word: [1] for word in words if len(word) [2] 4} print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 4 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths if length is greater than 3.
words = ['dog', 'elephant', 'cat', 'lion'] result = { [1]: [2] for word in words if len(word) [3] 3 } print(result)
The dictionary comprehension uses word.upper() as keys, len(word) as values, and filters words with length greater than 3 using >.