AP CSP CodeX - Mission 8: Answer Bot

Mission 8 Lesson Plan

Mission 8: Answer Bot

Students use lists and random numbers to program the CodeX to display random answers and colors.

⏰ 45 min 🎯 Grades 9-12 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

This lesson introduces random numbers: different ways to generate them and use them in code. The mission includes a lot of code review, as well as new code. In Objective 5, students create a list of answers. After Objective 7, students practice their programming skills by creating a function, adding a kill switch, and clearing the screen and pixels at the end of the program.

🎯 Mission Goal: Students will use a list and a while loop to create a group of random answers.

🎯

Learning Targets

  • I can create a list to use abstraction in my code.
  • I can apply properties of lists in my program.
  • I can use randomization with lists.
  • I can create and call a function.
💡

Key Concepts

  • Random number generators are crucial for many computer applications.
  • Lists can be used for a variety of purposes and uses in a program.
✅

Assessment Opportunities

☑️

Success Criteria

  • Program a button to print a random number
  • Select a random item from a list and print it
  • Select a random color from COLOR_LIST and use it to light up pixels
  • Create a function and call it in the main program
📁

Digital Resources

🧰

Classroom Materials

  • ▸CodeX
  • ▸USB-C cable
  • ▸Computer
🌍

Real-World Applications

🎮Games, where there should not be an obvious pattern for the human player to learn.
🔐Cryptography, where randomness helps secure stored passwords and messages.
🔬Scientific studies, where statistical sampling requires random selection.
🚀

Extensions & Cross-Curricular

ExtensionStudents who finish early can complete the challenge: use a while loop in the pixel color function instead of repeating the same line of code 4 times. This is extra practice with iteration, which is required for the Create PT.
🔤

Vocabulary

▾
Range - A sequence of numbers you can iterate over. You must provide at least the stop (or last) number in the sequence. Optional: you can provide the start (or first) number in the sequence and also the step, if other than increasing by 1.
Constant - A named value that doesn't change during the run of the code. By convention, constants are represented with ALL CAPS.
🐍

New Python Code

▾
import randomImport all the functions in the random module (library).
number = random.randrange(10) number = random.randrange(1, 6)Generate a random integer. The first example gives a number between and including 0 to 9. The default starting number is 0. The second example gives a number between and including 1 to 5. Integers will include the starting number and one less than the ending number.
display.print(number, scale=3)Change the size of the text by using the keyword parameter scale. If the scale is too big, the text will appear as gibberish or shapes on the display screen. scale=1 is the default size.
color = random.choice(COLOR_LIST) my_choice = random.choice(answers)Select a random item from a list.
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03 3A-AP-13 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-21

CSTA Standards - Grades 11-12

3B-CS-02 3B-AP-10 3B-AP-14 3B-AP-16 3B-AP-22 3B-AP-23

AP CSP Framework

AAP-1.C - Represent a list or string using a variable.
AAP-1.D - Develop data abstraction using lists to store multiple elements, and explain how the use of data abstraction manages complexity in program code.
AAP-2.N - Write expressions that use list indexing and list procedures.
AAP-3.E - Write expressions to generate possible values, and evaluate expressions to determine the possible results.
Computational Thinking Practice 3.A - Generalize data sources through variables.
Computational Thinking Practice 3.B - Use abstraction to manage complexity in a program.
📝
Preparing for the Lesson
  • The assignment is best completed digitally. Prepare the assignment to give through your LMS.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.

🧑‍🏫
Teacher Notes
  • This lesson introduces random numbers: different ways to generate them and use them in code.
  • The mission includes a lot of code review, as well as new code. Encourage students to do as much code on their own as they can, and use CodeTrek to check their work, or as a hint when needed.
  • Objective 5 has students create a list. Encourage students to use their own lists, and not the one in CodeTrek. Also encourage them to have more than three items.
  • After Objective 7, students will practice programming skills by creating a function, adding a kill switch, and clearing the screen and pixels at the end of the program. If students don't get all of the additions complete, that is okay. But they should try.
  • An additional challenge is given for any students finishing the program and having extra time. It is not required, but good for extra practice with iteration, which is required for the Create PT.
  • If you have time at the end of the lesson, use the Mission 8 Kahoot! Review.
  • Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions, and additional information.
🗺️

Lesson Outline

This outline gives the narration for one way to present the lesson.

🗣️Warm-up

Use a discussion strategy, like journaling, working at boards, selecting random students, or a form of think-pair-share.

This is a project with practical applications. In our previous program, the programmer or the person running the program had control over when something happened or what image appeared. However, in real life and in computer applications, we might have a lot of randomness. What are some examples of when we need something randomized?

Discuss real-world applications:

  • Video games
  • Secure password encryption
  • Real-world simulator trainers
  • Scientific statistical sampling
💻Activity - Mission 8

Randomly group students into pairs for pair programming (or they can work individually).

Students log in to one computer. Two computers can be used if they want to have the activity guide open on one computer and CodeSpace on the other computer.

Students go to make.firialabs.com and should be at the beginning of Mission 8.

Teaching tip - Objective 1: The code in this objective will cause an error. The instructions clearly state this, but students aren't always good at reading the instructions. The assignment document asks them if they know what the error is and how to fix it. They will do this on the next objective, but hopefully they remember before the instructions help them.
Teaching tip - Objective 3: This objective shows students an additional parameter to display.print. I recommend using the keyword "parameter" so they become familiar with it. The instructions have them use scale=3. They can try different numbers for the scale. When the scale makes the text too big for the screen, it will turn into strange lines and not be readable. When this happens, they need to adjust the scale smaller.
Teaching tip - Objective 5: Students create a list. The list can contain any text that is school appropriate. The example is for food, but it can be anything they are interested in (sports, fashion, food, games, etc.).
Teaching tip - Objective 6: Students will use a list for colors, but they DO NOT need to create it. The instructions show the list, but they do not need to type it. The list used has all the built-in colors for the neoPixels, and the list is already created. Students simply need to access it: COLOR_LIST.
🧩Activity - After Objective 7
Teaching tip - After Objective 7: With this activity, students have a chance to practice some of the programming skills they have been learning. Spend the time you have on these additions, but if students don't do them all, that is okay. They can be done in any order.
Teaching tip - Addition #1: Clear the screen before printing an item in the list. Just add display.clear() before the display.print() statement.
Teaching tip - Addition #2: Create a function to change the pixel colors. The name of the function should be descriptive. Then students can cut and paste the code from the main program to the function, and call the function in the main program.
Teaching tip - Addition #3: Add a kill switch. Students have done this a couple times already, so they should be able to do this without a problem.
Teaching tip - Addition #4: After the program ends (pressing the kill switch), clear the screen and the pixels. One way is to use display.clear() and pixels.off(). This code is NOT inside the while True: loop, or indented.

Example solutions are given for the program as given in the mission, with additions, and with the challenge.

✅ The assignment is complete and ready to turn in.

🧑‍🤝‍🧑Wrap-Up

Optional. Use a formative assessment for the wrap-up.

Formative assessment:

  • Daily reflection journal
  • Mission 8 Kahoot! Review (in class or individual)
  • Exit ticket or group review on generating random numbers