How can you modify a content creation agent workflow to log each step's start and end times using Python's datetime module?
hard📝 Application Q9 of 15
Agentic AI - Real-World Agent Applications
How can you modify a content creation agent workflow to log each step's start and end times using Python's datetime module?
Aimport datetime
for step in steps:
start = datetime.datetime.now()
process(step)
end = datetime.datetime.now()
print(f'{step} started at {start} and ended at {end}')
Bimport datetime
for step in steps:
process(step)
print(f'{step} processed')
Cfor step in steps:
start = time.now()
process(step)
end = time.now()
print(f'{step} started at {start} and ended at {end}')
Dimport datetime
for step in steps:
start = datetime.now()
process(step)
end = datetime.now()
print(f'{step} started at {start} and ended at {end}')
Step-by-Step Solution
Solution:
Step 1: Use correct datetime import and method
datetime.datetime.now() is the correct way to get current time.
Step 2: Check code correctness
import datetime
for step in steps:
start = datetime.datetime.now()
process(step)
end = datetime.datetime.now()
print(f'{step} started at {start} and ended at {end}') imports datetime, uses datetime.datetime.now(), and logs times correctly.
Final Answer:
import datetime
for step in steps:
start = datetime.datetime.now()
process(step)
end = datetime.datetime.now()
print(f'{step} started at {start} and ended at {end}') -> Option A
Quick Check:
Use datetime.datetime.now() for timestamps [OK]
Quick Trick:Use datetime.datetime.now() to get current time [OK]
Common Mistakes:
Using datetime.now() without module prefix
Using time.now() which does not exist
Not importing datetime module
Master "Real-World Agent Applications" in Agentic AI
9 interactive learning modes - each teaches the same concept differently