Close
Close full mode
logoMakeCode AP CSP

Refining and Debugging Algorithms

Summary

Materials

Instructional Activities and Classroom Assessments

  1. Algorithm Review (5 minutes)
  2. Building Blocks of Algorithms (10 minutes)
  3. Create Program for Add All Ages in the Room (10 minutes)
  4. Debugger Mode (10 minutes)
  5. Commenting on Your Code (5 minutes)
  6. Modify your Program (5 minutes)
  7. Reflection/Homework (5 minutes)

Learning Objectives

  • AAP-2.A Express an algorithm that uses sequencing without using a programming language. 2.A
  • AAP-2.M For algorithms:
      1. Create algorithms. 2.A
  • CRD-2.G Describe the purpose of a code segment or program by writing documentation. 4.A

Essential Knowledge

  • AAP-2.A.1 An algorithm is a finite set of instructions that accomplish a specific task.
  • AAP-2.M.1 Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.
  • CRD-2.G.1 Program documentation is a written description of the function of a code segment, event, procedure, or program and how it was developed.
  • CRD-2.G.3 Programmers should document a program throughout its development.

Details

1. Algorithms review (5 minutes)

Remind students of the Add All Ages in the Room algorithm that they created yesterday. Note that to make it work we had to hardcode everyone's age. But there is a way for a user to input each person's age.

2. Building blocks of algorithms (10 minutes)

  • Connect flowchart shapes to the types of programming constructs commonly used in algorithm implementations:
  • Sequence
  • Selection
  • Iteration
  • Review an everyday algorithm and identify the sequence, selection, and iteration constructs.
  • Discuss the add ages of people in the room algorithm.
  • Define data values.
  • Discuss the two types of data values:
  • Constants
  • Literal constants
  • Named constants
  • Variables

3. Create program for Add All Ages in the Room (10 minutes)

  • Guide students through the process of creating a program for adding all ages in the room:
    • Create variables
    • Ask for number
    • How many people are in the room?
    • Set N
    • Repeat block
    • Ask for number
      • How old are you?
    • Change N by
    • Splash
      • Error message for argument of type number
      • Join block

4. Debugger mode (10 minutes)

  • Discuss what debug programs do.
  • Introduce MakeCode debugger mode.
  • Encourage students to run the program with the debugger mode open.
  • Point out to students the variables that are in the debugger area when they run the program:
    • N - should change as they enter new ages.
    • Index - keeps track of how many times the program asks How old are you and changes N.

5. Commenting on your code (5 minutes)

  • Explain what program documentation is and its purpose.
  • Discuss how programmers use comments to document their development.
  • Show students how to make comments in MakeCode.
  • Encourage students to comment on their program.
  • Encourage students to save their work at this point and add the link here - My Add Ages in the Room Program:
    • They can do this by create a Link to their programβ€―with the Share button.
    • Depending on your class collaboration system, you can have students copy and paste their program links in an email, LMS system, Class OneNote, or other tool.
    • Alternately, they can download their programs as .png files on their local computers or on a shared file system.
    • Note - by default most browsers will download files to the "Download" folder on a computer.β€― You can change this behavior if you want by configuring the browser settings (instructions in PowerPoint deck).

6. Modify your program (5 minutes)

  • Ask students if there is a different way to calculate your total ages:
  • Can you create a different way to calculate all of your ages?
  • Is there a way to accurately calculate your ages with fewer entries?
  • Encourage students to explore different commands to see if they can develop a different way to calculate the ages of everyone in the room.

7. Reflection (5 minutes)

If you run out of time, you may also assign this as individual homework. Students should complete their reflection in their OneNote.

  • What is the origin of the term debug?
  • How does a debugger help your coding?
πŸ“˜ Unit 3 - AAP Part 1 β€” Previous
Day 3
Next β€” πŸ“˜ Unit 3 - AAP Part 1
My Add Ages in the Room Program