Complete Python Series · Part 19 of 29
Assignment 06-video-pipeline
NextGen CTO — Python Assignments
A collection of practical Python exercises based on real-world scenarios from the NextGen CTO learning platform. Each assignment includes starter code, hints, a complete solution, and an explanation.
Exercise: NextGen CTO Video Processing Pipeline
Learn to control a fixed-duration processing job using for, continue, break, and for-else, while tracking a running total.
Problem statement
NextGen CTO processes course videos in an eight-hour batch. In this simulation, each active hour processes 100 video segments. Maintenance hours process nothing, and a critical error stops the batch immediately. If the loop finishes without a critical error, certify the batch as completed, even if some hours were spent in maintenance.
Task requirements
- Initialize
total_processedto zero. - Iterate over hours 1 through 8 using
range(). - Read the processing status (
Active,Maintenance, orError) usinginput(). - Skip maintenance hours using
continue. - On
Error, printCritical Failure! Stopping Pipeline!and exit usingbreak. - On
Active, add 100 to the running total. - Use the loop's
elseblock to printBatch completed successfullyonly if nobreakoccurred. - Print the total number of processed video segments after the loop.
Constraints
- Assume inputs are exactly
Active,Maintenance, orError(case-sensitive). - Use a
forloop withrange(1, 9)and afor-elseblock. - Use
breakandcontinue; do not use a separate completion flag. - Each active hour processes exactly 100 segments.
Good luck trying the exercise!
Starter code
total_processed = 0
print("Starting 8-hour video processing batch...")
# TODO: Write a for loop for hours 1 through 8
# TODO: Read the processing status
# TODO: Skip maintenance using continue
# TODO: Stop on error using break
# TODO: Update total_processed for an active hour
# TODO: Add a for-else block to confirm completion
# TODO: Print the final total
Expected output
Starting 8-hour video processing batch...
Hour 1 status: Active
Hour 2 status: Maintenance
Hour 3 status: Active
Hour 4 status: Error
Critical Failure! Stopping Pipeline!
Total video segments processed: 200
Hints
range(1, 9)generates the integers 1 through 8.continueskips the remaining statements in the current iteration.breakexits the loop immediately.- Align the loop's
elsewithfor, not with anifstatement. It runs when the loop finishes without abreak.
Solution: NextGen CTO Video Processing Pipeline
The solution uses a running total to track processed video segments and a for-else block to distinguish normal completion from early termination.
total_processed = 0
print("Starting 8-hour video processing batch...")
for hour in range(1, 9):
status = input(f"Hour {hour} status: ")
if status == "Maintenance":
continue
if status == "Error":
print("Critical Failure! Stopping Pipeline!")
break
if status == "Active":
total_processed += 100
else:
print("Batch completed successfully")
print(f"Total video segments processed: {total_processed}")
Solution explanation
- Lines 1–2: Initialize the running total and announce the batch.
- Lines 4–5: Iterate over eight hours and capture the status for each hour.
- Lines 7–8: Skip maintenance hours without changing the running total.
- Lines 10–12: Report a critical error and terminate the loop immediately.
- Lines 14–15: Add 100 segments for each active hour.
- Lines 16–17: Execute the loop's
elseonly when all iterations finish without abreak. Maintenance does not prevent this block from running. - Line 19: Display the final total regardless of how the loop ends.
Test cases
This exercise simulates processing status; it does not process actual video files. Completion means no critical error occurred, not that every hour was productive.