About this lesson
This lesson sequence intentionally uses a visual based programming tool to introduce designing and validating algorithms. Those students who complete this task can move to code the result in any text based language with which they are familiar.
Year band: 9-10Curriculum Links Assessment
Note: Criteria are cumulative
|Quantity of knowledge||Quality of understanding|
|Design and validate algorithms||No evidence of understanding||Student is able to build a program using Scratch to play some version of the game||Student is able to build a working program using Scratch to play a version of the game with more than three responses||Student is able to build a working program using Scratch to play a full version of the game and with the option of playing again||Student is able to build a working program using Scratch to play a fully tested version of the game, with error messages for invalid entries by users|
- Students first play the simple game against the teacher.
- Students then play the more sophisticated version of the game against the teacher.
Learning map and outcomes
Students learn to design an algorithm to solve a problem and describe algorithms using flowcharts and structured English; for example, START, END, IF and UNTIL.
They trace algorithms for a given input, using desk checking, and develop test cases that correspond to the requirements of the specifications; for example, validating program behaviour on a range of valid and invalid user input.
Building the basic Hi-Lo game in Scratch
Some people who are strong visual thinkers prefer to use flow charts to develop the basis for an algorithm.
- Introduce both flowcharts and structured English.
- Teach the basic control structures both in flowchart and structured English forms.
- Issue the 'Hi Lo flowchart worksheet 1'.
- Students cut up the symbols on their 'Hi Lo flowchart worksheet 1', and arrange them on a piece of paper to form a logically correct flowchart. They draw flow lines where required and add the True/False labels.
- Initial each correct flowchart. Ask those students to construct an equivalent version using structured English.
- Explain that structured English is very similar to pseudocode, but it tends not to use as many mathematical symbols.
Often, people start with structured English and/or a flowchart, convert it to pseudocode and then write executable code.
Explain that structured English avoids mathematical symbols and uses words wherever possible.
See Teacher Introduction for more information.
- Demonstrate the basics of Scratch.
- Ask what differences exist between scripts in structured English and Scratch.
- Assist students to locate each of these standard programming features, which all appear in the Scratch program the students will develop.
- Algorithm (whole program)
- Initializing a variable
- Operators (arithmetic and relational)
- Assist students to use Scratch to convert their structured English into a working Hi-Lo program.
- Assist students modify their programs to include a counter that reports the number of tries.
This will require the use of two 'Join' operators:
Building the more sophisticated Hi-Lo game in Scratch
- Discuss with the class what changes would need to be made to their earlier algorithm to play the second more sophisticated version of this game, using the terms: 'boiling' ,'hot', 'warm', 'cold' or 'freezing', with these rules:
- boiling: within 5
- hot: within 10
- warm: within 20
- cold: within 40
- freezing: greater than 40.
Note: Structured English is easier to use when many choices exist, as is the case here.
- Having established this, ask if flowcharts or structured English would be more helpful in developing the new algorithm.
- Students cut up the symbols on their 'Hi Lo flowchart worksheet 2' . They arrange them on a piece of paper to form a logically correct flowchart. They draw flow lines where required and add the True/False labels.
- Students modify their written algorithm using structured English to create the more sophisticated version of this game using the terms: 'boiling' ,'hot', 'warm', 'cold' or 'freezing'.
- Students now modify their Scratch program using their new structured English algorithm to play this latter version. This is not a trivial exercise as there are pitfalls that will illustrate well the necessity for desk checking.
Here are some common errors and challenges:
- Students need to find a method of testing if a guess is within a range of the secret integer. However, they encounter negative integers and must discover the ABSOLUTE VALUE function, which is provided in Scratch as one of many functions on the dropdown attached to the SQRT function.
- Students put the conditions in reverse order and thus guesses are immediately satisfied by the first test.
- Students use nested IF ... THEN instead of nested IF ... THEN ... ELSE.
- Students neglect to reset GUESS and to increment COUNT inside the repeat loop.
- Boundary conditions can be challenging to get right (for example, a guess 'within 20' will be satisfied by ABS(guess-secret)=20. There is no less than or equal to in Scratch, so students must use another approach, such as employing the OR statement or using <21 instead.
- Explain and demonstrate desk checking.
- Class discussion establishes suitable test data for this program by forcing 65 to be the secret number.
(Students to test each of: following:
within each range, boundaries, equal to secret number, decimal entries, negative integers, out-of range integers, invalid entries such as words, null entry, etc)
- Students prepare a set of values to desk check, including invalid data types and out-of-range values (eg negative integers, integers greater than 100).
- Students modify their programs to force the SECRET integer to be, say, 65 to enable all students to create comparable test cases.
- Students desk check each other's programs using a table, and mark as either pass or fail.
- Ask for suggestions of another real-life game that could be programmed (eg Rock/Paper/Scissors, Nim or Noughts and Crosses).
- Students discuss whether they found the flowchart tool or the pseudocode/structured English more helpful.