B. batch_report = [batch_id: 101, start_time: '08:00', status: 'complete']
C. batch_report = (batch_id=101, start_time='08:00', status='complete')
D. batch_report = 'batch_id=101; start_time=08:00; status=complete'
Solution
Step 1: Identify correct data structure syntax
In SCADA system configs, batch reports are often stored as key-value pairs in dictionaries or JSON-like objects.
Step 2: Check each option
batch_report = { 'batch_id': 101, 'start_time': '08:00', 'status': 'complete' } uses correct dictionary syntax with keys and values. Options A and C use invalid syntax for dictionaries. batch_report = 'batch_id=101; start_time=08:00; status=complete' is a string, not a structured entry.
Which Python code correctly calculates and prints the summary?
hard
A. duration = batch['end'] - batch['start']
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
B. from datetime import datetime
start = datetime.strptime(batch['start'], '%H:%M')
end = datetime.strptime(batch['end'], '%H:%M')
duration = (end - start).seconds // 60
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
C. duration = int(batch['end']) - int(batch['start'])
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}")
D. print(f"Batch {batch['id']} took {batch['end'] - batch['start']} minutes and is {batch['status']}")
Solution
Step 1: Parse time strings to datetime objects
Use datetime.strptime with '%H:%M' format to convert 'start' and 'end' strings to datetime objects.
Step 2: Calculate duration in minutes
Subtract start from end to get timedelta, then convert seconds to minutes using integer division.
Step 3: Print formatted summary
Use f-string to print batch ID, duration, and status clearly.
Final Answer:
from datetime import datetime
start = datetime.strptime(batch['start'], '%H:%M')
end = datetime.strptime(batch['end'], '%H:%M')
duration = (end - start).seconds // 60
print(f"Batch {batch['id']} took {duration} minutes and is {batch['status']}") -> Option B
Quick Check:
Parse times + timedelta = correct duration [OK]
Hint: Convert times to datetime before subtracting [OK]