Home · Academy · Robotics & Coding · Algorithms · Algorithm Mini Project: Smart Bag Check

Algorithm Mini Project: Smart Bag Check

Use the whole module to design, pseudocode, test and debug a smart bag-check algorithm.

LESSON COMPASS

What will you use this page for?

Core idea

To finish this module, we design an algorithm that checks whether your bag is complete for the day's lessons, bringing sequence, condition, repetition, variables and input/output together in a single project.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Finding the bug A student wrote the function but got "Missing" even in scenario 1. Checking the code, they found this line: if book in in_bag: # wrong missing.append(book) The condition is reversed: it counts a book as missing when it is in the bag. The fix is to use not in : if book not in in_bag: # correct…

Next connection

Programming with Scratch module and the Robotics & Coding Starter Quiz: We move algorithmic thinking into a real program built from blocks, and test what we have learned with a short quiz.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration45–75 min
PrerequisiteComparing Multiple Solutions
ContentProject guide · 1,670 words
Last updated

One-sentence summary

To finish this module, we design an algorithm that checks whether your bag is complete for the day's lessons, bringing sequence, condition, repetition, variables and input/output together in a single project.

Why does it matter?

A small project is the best way to see whether we have really learned a module. The pieces we studied one by one (ordering steps, writing a condition, building a loop) look easy on their own. Using them together is a little harder, and that is the real skill.

This project is a teaching template; we are not claiming that we built a real device. The goal is to practise turning an everyday problem into clear steps and then testing the solution. The same way of thinking will help later in Scratch, in Python and in robotics projects.

Step 1: Define the problem and requirements

Before writing any code, we need to state clearly what we are solving. A vague problem produces a vague solution.

Problem statement

Before leaving for school in the morning, we want to check that the bag is complete for today's timetable. If something is missing, the program should say which item is missing; if everything is there, it should say "ready."

Requirements

Notice that all five pieces of the module are here. The order of steps is sequence, the "if it is missing" decision is a condition, going through each lesson is repetition, the list that holds the missing items is a variable, and the lesson list and screen messages are input/output.

Step 2: Plan the variables and the logic

List of variables

List of variables table
VariableWhat it holdsExample value
lesson_listToday's lessons["Maths", "Science", "PE"]
in_bagItems already in the bag["Maths book", "Pencil case"]
needed_itemThe book each lesson needs"Science book"
missingItems that were not found["Science book"]
readyIs the bag complete?True / False

Pseudocode

Start
receive lesson_list
receive in_bag list
set missing to an empty list

Repeat for each lesson in lesson_list
  needed_item = the book of the lesson
  If needed_item is not in in_bag
    add needed_item to the missing list

If pencil case is not in in_bag
  add "Pencil case" to missing list
If water bottle is not in in_bag
  add "Water bottle" to missing list

If the missing list is empty
  print "Bag is ready"
Otherwise
  print the missing items
End

Text-based flowchart

        [Start]
           |
   [Receive lesson list]
           |
   [missing = empty list]
           |
   <Any lesson left to check?>
      Yes |            \ No
           v             \
 <Book in the bag?>       \
    No  |    \ Yes         \
        v     \             v
[add to      (next     <Is missing empty?>
 missing]     lesson)   Yes |     \ No
        \     /             v      v
     (back to loop)  [Bag is ready] [Print missing]
                             \       /
                              [End]

Step 3: Write it in Python and test it

When we translate the pseudocode into a real language, we can see whether the logic works.

def check_bag(lesson_books, in_bag):
    missing = []
    for lesson in lesson_books:
        book = lesson_books[lesson]
        if book not in in_bag:
            missing.append(book)
    for item in ["Pencil case", "Water bottle"]:
        if item not in in_bag:
            missing.append(item)
    if len(missing) == 0:
        return "Bag is ready"
    return "Missing: " + ", ".join(missing)

Three test scenarios

Three test scenarios table
#InputExpected output
1All books present, pencil case and water bottle presentBag is ready
2Science book absent, rest presentMissing: Science book
3Maths book and water bottle absentMissing: Maths book, Water bottle

Running the scenarios by hand and comparing them with the expected output is the most honest way to show that the algorithm actually works.

Mini practice

Write out your own bag in a table. Run the check_bag function above on paper or on a computer. Then add a fourth test scenario: for example, what happens if yesterday's book is in the bag by mistake? Does the program notice this as an "extra item," or does it ignore it? Write your answer in one sentence.

Project strengthening plan

A working demonstration is not enough for Algorithm Mini Project: Smart Bag Check. A strong project also makes its aim, user, limits, test conditions and failed attempts visible. Use the context of a route that guides a robot safely to a classroom target to produce a clear algorithm, pseudocode and a test table. Although the lesson aims to “Use the whole module to design, pseudocode, test and debug a smart bag-check algorithm”, do not present an unmeasured result as a confirmed success.

1. Project summary and scope

Write three sentences: What problem are you solving, who is affected by it, and what will the first version deliberately not do? Stating what is outside the scope does not weaken a project; it makes the project finishable. Describe the connection between Step 1: Define the problem and requirements and Requirements as the main assumption, then name the test that can confirm or reject it.

2. Acceptance criteria

Do not leave an acceptance criterion for “Algorithm Mini Project: Smart Bag Check” as a vague statement such as “it works”. Choose an observable measure such as time, distance, correct trials, screen width or user steps. When direct measurement is difficult, record whether the same behaviour appears in three consecutive trials.

3. Test matrix

3. Test matrix table
TestConditionExpectedActual resultNext decision
NormalStandard input and complete setupThe core task is completedFill in during the testKeep it or make a small improvement
BoundaryLowest or highest accepted valueThe system remains stableFill in during the testReview the threshold or rule
ErrorMissing, wrong or unexpected inputA safe and clear responseFill in during the testAdd error handling
RepeatAt least three trials under the same conditionSimilar resultsFill in during the testInvestigate the source of inconsistency

4. Version log

For every version of “Algorithm Mini Project: Smart Bag Check”, record the date, the one main decision changed, the reason and the test result. A first version that fails is evidence about which assumption involving Step 1: Define the problem and requirements or Requirements should be reconsidered. Remove personal information and private background details from images.

5. Presentation and self-review

Prepare a two-minute explanation of “Algorithm Mini Project: Smart Bag Check”: the problem, the solution approach, the most important result for a route that guides a robot safely to a classroom target, and the next step. Instead of saying the project is complete, state which part has been verified and which part still needs development.

Common mistakes

Finding the bug

A student wrote the function but got "Missing" even in scenario 1. Checking the code, they found this line:

if book in in_bag:      # wrong
    missing.append(book)

The condition is reversed: it counts a book as missing when it is in the bag. The fix is to use not in:

if book not in in_bag:  # correct
    missing.append(book)

Other common mistakes

Safety note

This lesson is a thinking project that runs entirely on paper and screen. If you later want to turn it into a real prototype (for example a light warning or a box with a sensor), any step involving batteries, motors, cutting tools or hot surfaces should be done under adult supervision. Never work with mains electricity.

Lesson summary

Check questions

  1. What job does the loop do in this project?
  2. What is the missing variable for, and why is it emptied before the loop?
  3. Why is not in needed in the condition instead of in?
  4. What is the expected output of test scenario 3?
  5. If you turn this project into a real device, which safety rule would you follow?

Answers

  1. It goes through each lesson in the list one by one and checks whether that lesson's book is in the bag, so we do not have to write the same check by hand over and over.
  2. It collects the items that were not found. It is emptied before the loop so that missing items from a previous check do not mix into the new result.
  3. We want to count an item that is not in the bag as missing. not in means "if it is not in the list"; using in reverses the logic.
  4. Missing: Maths book, Water bottle
  5. Doing any step with batteries, motors, cutting tools or hot surfaces under adult supervision, and staying away from mains electricity.

Source and verification note

For “Algorithm Mini Project: Smart Bag Check”, verification focuses on whether the relationship between Step 1: Define the problem and requirements and Requirements remains consistent across examples. The algorithms in this lesson are checked by tracing sample inputs by hand and comparing them with expected outputs. Pseudocode is used to make the reasoning sequence visible without tying it to one programming language.

Next lesson

Programming with Scratch module and the Robotics & Coding Starter Quiz: We move algorithmic thinking into a real program built from blocks, and test what we have learned with a short quiz.

Start QuizBack to Algorithms
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.