Stop within each batch

A packing station records package masses in grams. Within each batch, zero marks the point where processing should stop; any later readings in that batch are ignored. The following Python program prints the number of packages processed from each batch.


Python
batches = [[8, 0, 5], [0, 6], [4, 7, 0, 9]]

for batch in batches:
    accepted = 0
    for mass in batch:
        if mass == 0:
            break
        accepted += 1
    print(accepted)


Complete the table with the exact integer printed for each batch, in the order the batches appear.

Batch indexPrinted package count
0
1
2

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Nested Lists Questions: