KIPR · Botball Explorer
Activity Sections

Unit 1 · Big Idea 3

Computers Make Decisions Using Rules

Student Lab · The Freight Sorter

Unit Guiding Question
How can a machine understand and act within the world?
Big Idea
Computers Make Using Rules
AI Literacy Thread
Intelligent systems identify patterns and use rules to make decisions.
CS1 Concepts
Classification · Logic · Pattern Recognition · Decision Making
Game Context
Freight Objects — sorting by type
What You Need
Explorer robot kit · game field · this lab sheet
Before you start: type your PIN in the box at the top of the page. Your teacher gave you this number. When you finish, press Submit & Download to turn in your work and save a copy.

Overview

So far, your robot has done exactly what you told it, in exactly the order you wrote it. Today that changes. You’ll write a program that makes a choice — it looks at a value and decides what to do based on a rule. The robot will sort freight: one action for one kind, a different action for another.

Core Insight

A decision is a rule the computer follows: “IF this is true, do one thing; OTHERWISE, do something else.”

The robot doesn’t “know” anything. It checks a value against a rule you wrote — and that is what makes it look intelligent.

By the end of this activity you will be able to:

  • Explain what a is and how an if statement uses one to make a decision.
  • Use if / else to make a robot take different actions for different values.
  • Predict what a program will do by reading its rule before you run it.
  • Connect rule-based decisions to how intelligent systems classify and respond to the world.

New This Time: Making a Decision

You already know , , and the commands k.motor(), k.msleep(), and k.ao(). Today you add one new tool: the if statement.

An if statement --- a rule the computer checks

An if statement checks whether something is true. If it is, the computer runs the indented code underneath it. If it is not, it can run a different after else instead.

freight_type = 1             # a number YOU set

if freight_type == 1:        # IF freight_type is 1...
    drive_forward()           # ...do this
else:                         # OTHERWISE...
    turn_right()              # ...do this instead

Change freight_type to a different number, and the robot makes a different choice — without you rewriting the rule.

== means "is it equal?"

Watch the symbol carefully. There are two equals signs in a rule, not one:

freight_type = 1      # ONE equals  =   SETS the value to 1

if freight_type == 1:  # TWO equals  ==  ASKS "is it equal to 1?"

A single = sets a value. A double == asks a question. Using one when you mean the other is one of the most common bugs in all of programming — so check it every time.

Phase 1 — Activate: The Bouncer at the Door

Imagine you are a bouncer at the door of an event. You have exactly one rule: if a person’s ticket says “VIP,” send them left; otherwise, send them right. You don’t know these people. You don’t judge them. You just check the ticket against the rule and act.

Send each person left or right by your rule:

PersonTicket saysLeft or Right?
1VIP
2General
3VIP
4General
5General

A bouncer follows a rule without deciding who “deserves” what. How is that like the way a computer makes a decision?

Phase 2 — Concept: Conditions, Rules, and Classification

A Condition Is a True/False Question

Every decision a computer makes starts with a condition — a question that is either true or false. freight_type == 1 is a condition. Right now it is either true (the value really is 1) or false (it is anything else). There is no “maybe.” This is called thinking: every condition is true or false, nothing in between.

Classification

When a computer sorts things into groups using rules, that is classification. A mail machine reads a ZIP code and sends each letter to the right bin. Your program reads a freight value and sends the robot in the right direction. Same idea: a rule turns information into an action.

Pattern Recognition

Rules let a system respond to a pattern instead of a single fixed case. Your one rule — “if type 1, go straight; else turn” — handles every freight value you could ever set, not just one. Write the rule once, and it works for the whole pattern of cases.

Example

“If the light is red, stop; otherwise, go.” That one rule covers every red light and every non-red light in the world. You don’t write a new rule for each intersection — the pattern is handled by a single condition.

In your own words: what is the difference between a program that follows a fixed list of steps and one that makes a decision?

Phase 3 — Plan

The Sorting Task

Your Goal

Your robot is a freight sorter. A freight value is set at the top of the program. Your robot must take one action if the freight is type 1, and a different action if it is anything else.

You choose what “type 1” and “anything else” mean for the robot — for example, drive straight to one bin, or turn toward another.

Step 1 — Write Your Rule in Plain English

Before any code, write your sorting rule as a sentence in the form “IF … THEN … OTHERWISE …”.

Step 2 — Predict the Two Outcomes

Fill in what the robot should do for each freight value.

If freight_type is……the robot should
1
anything else (2, 3, …)

Step 3 — Trace the Rule by Hand

Before you run anything, predict the robot’s action for each value. This is called tracing — following the rule the way the computer will.

freight_type set toCondition true or false?What the robot does
1
2
5

Phase 4 — Build & Run

Starting Code Template

Type this program into your robot . The rule lives inside main(). Change freight_type at the top to test both paths. Fill in the actions to match your Phase 3 plan.

#!/usr/bin/python3

# Unit 1, Big Idea 3: Freight Sorter

# Name: _______________________   Date: ___________

import os, sys
sys.path.append("/usr/lib")
import _kipr as k

DRIVE_SPEED = 50

# A number YOU set. Think of it as the freight you're sorting.

# Change this value and the robot makes a different decision.
freight_type = 1     # try 1, then try 2

def drive_forward():
    k.motor(0, DRIVE_SPEED)
    k.motor(3, DRIVE_SPEED)
    k.msleep(1000)
    k.ao()

def turn_right():
    k.motor(0, DRIVE_SPEED)
    k.motor(3, -DRIVE_SPEED)
    k.msleep(600)
    k.ao()

def main():

    if freight_type == 1:       # IF the freight is type 1...
        drive_forward()          # ...send it straight ahead
    else:                        # OTHERWISE (it's not type 1)...
        turn_right()             # ...send it to the right instead

main()

Run It Both Ways — Results

Run the program with freight_type = 1, then change it to 2 and run again. Record what the robot actually did.

freight_type valueWhat you predictedWhat actually happened
1
2

  • You used == (two equals) inside the if, not a single =
  • Every is indented to the same level
  • You tested BOTH values, not just one
  • The robot did something different for each value

Phase 5 — Debug

Decisions create a brand-new kind of bug: the robot does the wrong action, even though it runs without an error. That means the rule ran fine — but it was the wrong rule, or the value was not what you thought.

The most common decision bugs

Wrong value: If the robot turned when you expected straight, check what freight_type is actually set to at the top.

Incorrect indentation: Any line that is not indented correctly will cause an error.

Log

TryWhat went wrongWhy (your best guess)How you fixed it
1
2
3
4

Describe one decision bug you hit. Did the robot do the wrong thing, or refuse to run? How did you find the cause?

Phase 6 — Connect: The AI Literacy Bridge

Big Idea 3 --- AI Literacy Thread

Intelligent systems identify patterns and use rules to make decisions.

Your robot did not “understand” the freight. It checked a value against a rule you wrote and acted. Almost every intelligent system works this way underneath: an email app checks features of a message against rules and decides “spam or not spam.” A photo app checks patterns and decides “face or not a face.” The system is not judging — it is classifying with rules. The intelligence is in the rules, and a human wrote them.

Read each scenario. Think it through, then write your answer.

A self-checkout machine decides whether the item you scanned matches its weight. What is the rule it is checking? What happens when the rule is wrong?

Your freight sorter only knows two outcomes: type 1, or everything else. A real sorting system might have ten kinds of freight. What is one problem with a rule that lumps everything that isn’t type 1 into a single “else”?

Who is responsible when an automated system classifies something wrong — sends the wrong freight, flags the wrong email? Connect this to the fact that a person wrote the rule.

Phase 7 — Individual Reflection

Complete this section on your own.

1. What is a condition? Write a definition in your own words.

2. Explain the difference between = and ==. Why does it matter inside an if statement?

3. Today your robot took different actions for different values without you rewriting the rule. Why is making a decision more powerful than a fixed list of steps?

4. Complete this in 2–3 sentences: “Intelligent systems identify patterns and use rules to make decisions. This means that when an AI system classifies something wrong…”

Extension Challenges

Finished early? Try one or more of these.

Extension A — A Third Choice

  • Right now your rule has two outcomes. Add a middle case using elif: type 1 does one thing, type 2 does another, everything else does a third.
  • Trace your new rule by hand for freight_type = 1, 2, and 9 before you run it.

Extension B — Flip the Rule

  • Change your condition so the robot does the OPPOSITE — drives straight for everything except type 1.
  • What did you change? Did you change the condition, the actions, or both?

Extension C — Greater Than

  • == is not the only test. Try if (freight_type > 3) — “is the value greater than 3?”
  • Predict, then test: what does the robot do for values 1, 3, and 7?

Extension D — Two Rules in a Row

  • What happens if you write two separate if statements one after another, each checking freight_type?
  • Could the robot ever do two actions in one run? When would that be useful, and when would it be a bug?

Extension E — Random Freight

  • Real freight wouldn’t always be the same type every run. Add import random to the line after import _kipr as k, then use random.randint(1, 10) to generate a random freight_type each time your program runs.
  • Run it several times. Does your sorting rule still make the correct choice across many random values?

When you are finished, press the button to turn in your work and save a copy.

KIPR · Botball Explorer · Unit 1 Big Idea 3 — Student Lab