A lesson with Tokbit
Flowcharts, variables, a condition and a loop in two lessons. Students do not copy code: they build the program from blocks, run it step by step and see what happens inside. In the second lesson they change it themselves.
- For
- Learning the basics of algorithms, no programming experience needed.
- Length
- Two 45-minute lessons: Lesson 1 – How a program thinks and Lesson 2 – I change a program. The times allow for opening Tokbit, different paces and helping at the computer.
- Preparation
- Just a browser on a computer, tablet or phone and the address tokbit.app/en. No installation, no account.
- Lesson goal
- Students read a flowchart and explain what the program does by stepping through it; they change a program with a variable, a condition and a loop and check that it works. It follows the Czech curriculum (RVP ZV, Computing, Algorithms and programming): I-9-2-01 (explain an algorithm), I-9-2-05 (write and test a program with loops, branching and variables), I-9-2-06 (find and fix a bug).
How Tokbit works
- Run starts the program; output and input are on the retro screen. Step runs one block and highlights it in the flowchart.
- The Variables panel shows the values of variables while running.
- The circle to the left of a block is a breakpoint: the program stops at the block and continues with Step or Continue.
- An error while running (such as dividing by zero) stops the program, and the block is marked red with a message about what happened.
The lessons follow the PRIMM approach: in Lesson 1 students predict what the program will do, run it and investigate it by stepping; in Lesson 2 they modify it and make their own. Tasks for all examples are in Tasks for the examples.
Lesson 1 – How a program thinks
Goal: students read a flowchart, step through a program and see in the Variables panel what the program remembers.
5 min 1. Open Tokbit and a demo
- Students open tokbit.app/en in the browser. Without a computer, a tablet or phone works too.
- Teacher opens the Hello example on the projector, walks through the flowchart from Start to End and steps through it with Step: the block that is running is always highlighted.
15 min 2. Hello and Sum of numbers
- Students open Hello, step through it, type their name on the screen and press Enter.
- Discuss: Where is the name stored? (in a variable, shown in the Variables panel).
- Then Sum of numbers: they enter a small number (such as 4) and step through. Before each step they guess what will happen and watch the total grow in the Variables panel.
- Common mistake: typing text instead of a number. Tokbit shows a message at the Input block and asks again. Feel free to try it on purpose.
15 min 3. Guess the number: a condition and a loop
Guess the number: the computer thinks of a number from 1 to 100 and says “higher” or “lower”. You play until you guess it.
- Teacher shows the diamonds: a while loop (repeats while the guess is wrong) and the higher / lower conditions.
- Students play. Then they put a breakpoint (the circle to the left of a block) on the condition block and find the secret number in the Variables panel.
- Discuss: Which strategy is fastest? (halving the range, at most 7 guesses).
10 min 4. A small change and wrap-up
-
Change: in Guess the number, change the range to 1 to 50. Tap the
block with
randint(1, 100)and rewrite it torandint(1, 50), then fix the text “from 1 to 100” in the Output. Nothing moves, you only rewrite. - Check: play and use a breakpoint to check that the secret number is at most 50.
- Wrap-up: What do a variable, a condition and a loop do? Where can you see them in the flowchart?
Optional, for fast students: Temperature conversion converts Celsius to Fahrenheit (input, a calculation in an expression, output).
Lesson 2 – I change a program
Goal: students change a program with a condition and a loop on their own and check by stepping through it that it works.
5 min 1. Recap
- Open Guess the number and talk together about what the loop and the conditions do. Where are the guesses counted?
30 min 2. Task: at most 7 guesses
Change Guess the number so that the player has at most 7 guesses. When they run out, the program says which number it was thinking of.
-
Hint: add
and tries < 7to the loop condition and put a Condition after the loop that tells a win from a loss. Move the “You got it…” output into its Yes branch (Cut, then + in the branch and Paste), otherwise a loss prints both. - Check: play and lose on purpose; step through to check that the loop ends after the seventh guess.
- Common mistakes: no message for a loss, or “You got it” even after losing (the output stayed after the Condition). Stepping shows which way the program went.
- Time to help: this is where the class pace differs most; whoever is done helps a neighbour or continues with the extensions below.
- Solution: open the solution in Tokbit, or download the file (in Tokbit: menu next to the program name → Open from file).
10 min 3. Wrap-up
- How did stepping help you find a bug?
- Why does a while loop fit here (we do not know the number of rounds), and when is for better?
For fast students and next lessons
Faster students can score points by the number of guesses, or try their own function in the Factorial example. Next lessons can continue with functions, colours and sprites (the Rainbow and Ball examples or the Snake and Tic-tac-toe games in the Examples window).