1.15 Algorithm and Flowcharts- Python With Karel --Three Day Lesson
 
Karel Algorithms & Flowcharts - 3-Day Interactive Lesson

🤖 Karel Algorithms & Flowcharts

Interactive 3-Day Lesson for 7th Grade

Learn to think like a programmer!

🎮 Algorithm Kahoot Review

Formative Assessment - 10 Questions

Test Your Algorithm Knowledge!

Click on your answer for each question

Question 1: What is an algorithm?

A) A type of computer language
B) A step-by-step set of instructions to solve a problem ✅
C) A robot that follows commands
D) A type of flowchart symbol

Question 2: Which symbol represents a decision in a flowchart?

A) ⬜ Rectangle (Process)
B) ⭕ Oval (Start/End)
C) 🔷 Diamond (Decision) ✅
D) ➡️ Arrow (Flow)

Question 3: Karel needs to move until hitting a wall. Which control structure?

A) if statement
B) while loop ✅
C) for loop
D) if/else statement

Question 4: What are the three building blocks of ALL algorithms?

A) Variables, functions, loops
B) Sequencing, iteration, selection ✅
C) Input, process, output
D) Start, middle, end

Question 5: Karel takes all balls on one spot until none remain. Which loop?

A) for loop
B) while balls_present(): ✅
C) if statement
D) repeat 5 times

Question 6: What is pseudocode?

A) Fake code that doesn't work
B) Code-like writing that plans logic before programming ✅
C) Python code with errors
D) Comments in your code

Question 7: In the move_single_ball() function, what is the correct order?

A) move() → take_ball() → put_ball() → come_back()
B) take_ball() → move() → put_ball() → come_back() ✅
C) put_ball() → move() → take_ball()
D) come_back() → move() → put_ball()

Question 8: Karel picks up a ball IF one is present, ELSE puts one down. Which structure?

A) while loop
B) for loop
C) if/else statement ✅
D) sequencing only

Question 9: What does decomposition mean in algorithms?

A) Breaking big problems into smaller sub-problems ✅
B) Deleting code that doesn't work
C) Making code run faster
D) Testing your program

Question 10: Why create a flowchart BEFORE coding?

A) It's required by Python
B) It helps visualize logic and prevent errors ✅
C) It makes code run faster
D) Teachers require it for grades

🎯 Welcome to Algorithms with Karel!

What You'll Learn:

  • What algorithms are and why they matter
  • How to visualize algorithms using flowcharts
  • How to translate flowcharts into Python code
  • How to solve problems using Karel the Dog

🐕 Meet Karel!

Karel is a robot dog that follows your commands

🐕

Karel's Commands: move(), turn_left(), put_ball(), take_ball()

📖 Key Vocabulary

Algorithm

A step-by-step set of instructions to solve a problem

Flowchart

A visual diagram that shows the steps of an algorithm using symbols

Pseudocode

Code-like writing that plans logic before actual programming

Iteration

Repeating steps using loops (while, for)

Selection

Making choices using if statements

Sequencing

Executing steps in order, one after another

📅 Day 1: Introduction to Algorithms & Flowcharts

Time: 50 minutes

🎯 Today's Objective

Students will apply flowchart design principles to visualize a Python Karel algorithm using proper symbols and sequence.

🔥 Warm-Up (5 minutes)

Question: "What is an algorithm? Give one real-life example from your daily routine."

Examples: Making breakfast, getting ready for school, playing a video game level

📚 Part 1: What is an Algorithm? (10 minutes)

Definition

Algorithm: A step-by-step set of instructions to solve a problem.

Real-World Examples:

  • 🥪 Recipe for making a sandwich
  • 🚗 Directions to get to school
  • 🎮 Steps to complete a game level
  • 📱 Process to post on social media

Three Building Blocks of ALL Algorithms:

  • Sequencing - Steps in order
  • Iteration - Repeating steps (loops)
  • Selection - Making choices (if statements)

🎨 Part 2: Flowchart Symbols (10 minutes)

Start/End

Oval shape marks beginning or end

Process

Rectangle for actions like "move()"

🔷

Decision

Diamond for yes/no questions

➡️

Arrow

Shows flow direction

Key Rules: Always start with "Start" and end with "End". Decisions have two paths (Yes/No). Arrows show the order. Loops connect back to earlier steps.

👨‍🏫 Part 3: Teacher-Led Flowchart Example (15 minutes)

Problem: Karel moves forward until hitting a wall

Start
🔷 Is front clear?
↙ Yes          No ↘
move()            ⭕ End
↓ (loop back)
Karel Python - CodeHS Editor
1
2
3
def move_to_wall(): while front_is_clear(): move()

✏️ Guided Practice (10 minutes)

Practice Problem: Karel picks up a ball if one is present

Your Task:

  1. Write the algorithm in plain English
  2. Identify the decision point
  3. Draw the flowchart with proper symbols

🤔 Reflection Question

"Why is visualizing an algorithm with a flowchart helpful before coding?"

🏠 Homework

Draw a simple flowchart for one of these:

  • Karel moves forward 3 times
  • Karel turns right (using turn_left() three times)

📅 Day 2: Partner Flowcharts & Pseudocode

Time: 50 minutes

🎯 Today's Objective

Students will create a flowchart with a partner for a Python Karel algorithm and translate it into pseudocode.

🔥 Warm-Up (5 minutes)

Quick Quiz: Which control structure should Karel use to move forward until a ball is present?

  • A) for loop
  • B) while loop ✅
  • C) if statement
  • D) if/else statement

📺 Part 1: Move Stack Algorithm (10 minutes)

Problem: Move a pile of tennis balls one space east

Algorithm Steps:

  1. Move to the pile
  2. While balls are present:
    • Pick up one ball
    • Move forward
    • Put down the ball
    • Come back
  3. End
Karel Python - CodeHS Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Main algorithm def move_pile(): while balls_present(): move_single_ball() # Helper function def move_single_ball(): take_ball() move() put_ball() come_back() # Come back function def come_back(): turn_around() move() turn_around()

👥 Part 2: Partner Activity (20 minutes)

Work with your partner to:

  1. 1Write the algorithm in plain English (3 min)
  2. 2Identify all decisions and loops (2 min)
  3. 3Draw the complete flowchart together (10 min)
  4. 4Translate to pseudocode (5 min)

🤔 Reflection Questions

  • "How does breaking a problem into sub-algorithms make coding easier?"
  • "Where do decisions appear in your flowchart?"
  • "How did you show the loop in your flowchart?"

🎤 Partner Share-Out (5 minutes)

Selected pairs present:

  • One key decision in their flowchart
  • How they handled the loop
  • Where they used helper functions

🏠 Homework

Write pseudocode for this problem: "Karel moves to a wall, turns left, and moves forward twice."

📅 Day 3: Independent Project - Decorate the Wall

Time: 50 minutes

🎯 Today's Objective

Students will apply their algorithmic thinking skills to create a complete flowchart, pseudocode, and Python solution for the "Decorate the Halloween Wall" challenge.

🔥 Warm-Up (5 minutes)

Reflection: "What is the main advantage of writing pseudocode before writing actual Python code?"

Write 2-3 sentences and share with a neighbor.

🎃 Major Assignment: Decorate the Halloween Wall

The Problem:

Karel is preparing for Halloween by hanging jack-o-lantern lights along a wall. Karel must place lights (balls) only where there is a wall, avoiding doors and windows!

Requirements:

  • ✅ Karel starts in bottom-left corner facing East
  • ✅ Karel ends at top of wall facing North
  • ✅ Place a ball ONLY where right_is_blocked() is True
  • ✅ World height: 10 rows
  • ✅ Include comments for ALL functions

📝 Step-by-Step Process (30 minutes)

1Understand the Problem (5 min)

Answer these questions:

  • Where does Karel start? (Bottom-left, facing East)
  • Where should Karel end? (Top of wall, facing North)
  • When should Karel put a ball? (When right_is_blocked())
  • When should Karel NOT put a ball? (Doors/windows = right is clear)

2Plan Algorithm in Plain English (5 min)

  1. Move to the wall (go_to_wall)
  2. Turn left to face the wall
  3. While the front is clear:
    • If right is blocked → put ball
    • Move forward
  4. Check one last time: if right is blocked → put ball

3Create Your Flowchart (10 min)

Draw a complete flowchart using proper symbols:

  • ⭕ Start/End ovals
  • ⬜ Process rectangles for actions
  • 🔷 Decision diamonds for conditionals
  • ➡️ Arrows showing flow and loops

4Translate to Pseudocode (5 min)

Karel Python - CodeHS Editor
1
2
3
4
5
6
7
8
9
10
11
12
# Function to move to wall function go_to_wall(): while front_is_clear(): move() # Function to decorate wall function decorate_wall(): while front_is_clear(): if right_is_blocked(): put_ball() move() if right_is_blocked(): put_ball() # Main program go_to_wall() turn_left() decorate_wall()

5Implement Python Code

Karel Python - CodeHS Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Go until Karel hits a wall def go_to_wall(): while front_is_clear(): move() # Move along the wall # Put a ball where there isn't a door or gate def decorate_wall(): while front_is_clear(): if right_is_blocked(): put_ball() move() if right_is_blocked(): put_ball() # Main execution go_to_wall() turn_left() decorate_wall()
Testing Tips: Run your program in CodeHS. Check Karel's final position. Verify balls are only where walls exist. Test with different world configurations!

🤔 Reflection Questions

  1. "How did you decide where to put the decision diamond in your flowchart?"
  2. "What part of your algorithm could be reused in other Karel problems?"
  3. "Why is it important to test each function individually before combining them?"
  4. "What was the hardest part of translating your flowchart into code?"

📤 Submission Requirements

  • ✅ Flowchart (hand-drawn or digital)
  • ✅ Pseudocode
  • ✅ Python code with comments
  • ✅ Reflection responses

🌟 Extension Challenge (Optional)

Create Your Own Algorithm Challenge!

Design a new Karel problem that includes:

  • At least one loop
  • At least one decision
  • A clear start and end state

Create the flowchart first, then implement it in Python!

Useful links
Last updated  2025/10/24 03:48:47 PDTHits  56