Python Level-1 with Virtual Robotics - Mission 10: Fido Fetch

Mission 10 Lesson Plan

Fido Fetch

Students will train the CodeBot to follow commands using a Python dictionary and console inputs.

⏰ 2-3 hours 🎯 Grades 9-12+ πŸ’» CodeSpace πŸ€– Virtual CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

In this mission, students teach CodeBot to respond to typed commands using a Python dictionary. They use input() to take a command from the console, then build a dictionary of key:value command pairs where each value can even be a function call, turning CodeBot into a robot dog that sits, fetches, and gives a high-five on request. Students add and remove commands after the dictionary is defined, iterate over it to list every command available, and refactor away a long if:elif chain in favor of an efficient dictionary lookup.

🎯 Mission Goal: Students will train the CodeBot to follow commands using a Python dictionary and console inputs.

🎯

Learning Targets

  • I can give input through the console.
  • I can define and add key:value command pairs to a dictionary.
  • I can use function calls as values in a dictionary.
  • I can iterate over a dictionary.
  • I can use a dictionary of commands to control a robot dog.
πŸ’‘

Key Concepts

  • A dictionary has several benefits. You can search by key or value, and looking up values in a dictionary is more efficient than searching through a list of items to find a match.
  • You can add key:value pairs to a dictionary after it has been defined.
  • You can delete a key:value pair from a dictionary.
  • You can iterate, or traverse, over a dictionary.
βœ…

Assessment Opportunities

  • Quiz after Objective 3
  • Quiz after Objective 7
  • Code Tracing Chart as a debugging tool
  • Give students printed code from an objective and have them explain each line
  • Give extra practice with dictionaries
  • Submit final fido.py program
  • Review Kahoot
β˜‘οΈ

Success Criteria

  • Use the input() function to give a command.
  • Define a dictionary with different key:value pairs.
  • Add key:value command pairs to a dictionary.
  • Use functions as values in a dictionary.
  • Write an efficient program without using an if:elif statement for looking up values.
  • Use dictionary commands to control the robot dog (collect treats, get a high-five).
🧰

Classroom Materials

  • β–ΈComputer or Chromebook with internet access
🌍

Real-World Applications

πŸ’»Dictionaries are used in all types of software. They're an efficient way to search collections of items, much faster than checking a list one entry at a time.
β˜•Everyday objects like coffee makers and microwave ovens work the same way: you tell it which task to do, and it looks up the matching action.
🎯What other items can students think of that work this way? How could they use a dictionary to be efficient?
πŸš€

Extensions & Cross-Curricular

ExtensionAdd more commands and functions. You could incorporate LEDs, or have different barks, and even have actions like "rollover."
ExtensionUse a button to wake up the dog and have it ready for commands.
ExtensionUse a button to quit the program - the dog needs to take a nap!
Lang ArtsHave students write a short story about a robot dog.
MathThe final objective requires the robot dog to move around the floor and collect treats. A lot of angles and distances are involved. Use math to determine the path for the robot dog to take.
πŸ”€

Vocabulary

β–Ύ
Dictionary:A container that holds keys and values. It supports fast lookup of a value based on a given key. Dictionaries are defined with curly braces {}.
KeyError:Result when a key is given that is not in a dictionary.
Refactor:Improving the structure of your code by making major changes to the code while accomplishing the same task.
🐍

New Python Code

β–Ύ
value = dictionary[key] response = commands[command] Look up the value of a key:value pair.
dictionary['key'] = value commands['come'] = [30, 30] Add a key:value pair to a dictionary that is already defined.
for k in commands: print(k) Iterate over a dictionary (k stands for "key"). This example prints all keys to the console.
del_key = input('Command to forget: ') del commands[del_key] Remove a key:value pair from the dictionary.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 9-10

3A-CS-01 3A-CS-03 3A-DA-10 3A-AP-13 3A-AP-14 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-19 3A-AP-21 3A-AP-26

CSTA Standards - Grades 11-12

3B-DA-06 3B-DA-07 3B-AP-10 3B-AP-12 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-17 3B-AP-20 3B-AP-21 3B-AP-22 3B-AP-23

Certiport IT Specialist: Python Standards

1.1 1.2 1.3 1.4 2.1 2.2 3.2 4.1 4.2 5.1

PCEP: Certified Entry-Level Python Programmer

1.1 1.2 1.3 1.4 1.5 2.1 2.2 3.3 4.1 4.3
πŸ“
Preparing for the Lesson
  • This Mission is pretty straightforward - it's all about dictionaries. Review concepts or give extra practice as needed.
  • Remember that you must zoom into the environment to hear the speaker.
  • If needed, review accessing items from a list using index for Objective 4.

πŸ§‘β€πŸ«
Teacher Notes
  • This mission is a good time to review and re-emphasize abstraction in code. With the addition of dictionaries, students now have functions, lists, and dictionaries as tools for abstraction - compare levels of abstraction in hardware and software.
  • Meeting the last objective will be different for each student. When a "treat" is taken by the 'bot, a small green check will appear over it. Some trial and error and practice will be needed, but there is no time limit. If a student gets frustrated, just have them start over.
  • For the high-five goal, the 'bot just needs to move very fast. The 'bot can do it first, or last, or any time.
πŸ—ΊοΈ

Lesson Outline

πŸ—£οΈWarm-up / Hook

Ask students to name a machine that does something different depending on which button you press - a coffee maker, a microwave, a remote control. Each button triggers a different task. Connect this to the mission: CodeBot is about to become a robot dog that listens for typed commands and looks up the matching action in a Python dictionary.

1️⃣Objectives 1-3: Console Input and the Command Dictionary
  • Introduce input() to take a command from the console.
  • Define a dictionary of key:value command pairs and look up a value with commands[command].
  • Administer the Quiz after Objective 3.
Teaching tip:Use the Code Tracing Chart here, or give students printed code from an objective and have them explain each line.
2️⃣Objectives 4-5: Adding, Removing, and Iterating
  • Add a new key:value pair to a dictionary that's already defined: commands['come'] = [30, 30].
  • Iterate over a dictionary with for k in commands: to print all available commands.
  • Remove a command from the dictionary with del commands[del_key].
  • Review accessing items from a list using index if students need a refresher.
Teaching tip:Give students extra practice adding, removing, and iterating over dictionary entries before moving on.
3️⃣Objectives 6-7: Functions as Values
  • Use function calls as the values in a dictionary, so looking up a command runs the matching action directly.
  • Refactor an if:elif chain into a single, efficient dictionary lookup.
  • Administer the Quiz after Objective 7.
Teaching tip:This is a good time to re-emphasize abstraction in code - compare functions, lists, and dictionaries as different tools for the same job.
4️⃣Final Objective: Robot Dog Control
  • Use the finished command dictionary to control the robot dog: collect treats and get a high-five.
  • Have students submit their final fido.py program.
Teaching tip:A small green check appears over a treat once it's collected. Trial and error is expected here - there's no time limit, so if a student gets frustrated, just have them start over.
πŸŽ‰Wrap-up / Review

Close with the Level-1 Mission 10 Review Kahoot! to reinforce dictionaries, adding and removing commands, iteration, and using functions as values before moving on to the Unit 3 Remix & Assessment.