Python Level-1 with Virtual Robotics - Mission 10: Fido Fetch
Fido Fetch
Students will train the CodeBot to follow commands using a Python dictionary and console inputs.
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.pyprogram - 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).
Digital Resources
Classroom Materials
- βΈComputer or Chromebook with internet access
Real-World Applications
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
π
New Python Code
βΎ
k stands for "key"). This example prints all keys to the console.
π
Standards
βΎ
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
Certiport IT Specialist: Python Standards
PCEP: Certified Entry-Level Python Programmer
- 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.
- 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
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.
-
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.
-
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.
- 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.
- Use the finished command dictionary to control the robot dog: collect treats and get a high-five.
- Have students submit their final
fido.pyprogram.
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.