Build your first block program
Build, connect, move, detach, delete, and run a small block program, then read its Python equivalent.
Your own workspace, right here
Build this right beside the article. We start with one block and grow the same program gradually. Use an invented name and age, make predictions before each Run, and keep your own choices as you work. The complete reference stays folded at the end.
The article and your practice editor work together. On a laptop the editor stays beside the text. On a narrow screen, Practice opens it; close that panel to return to the same place in the article. Expand gives a complicated program more room. You can build from an empty canvas with Add blocks, or load any pictured stage with Try this stage. Loading is an editable starting point, not a test or an automatic completion. It replaces the program currently in the mini editor, and Undo restores the previous version.
The pictures use the same block definitions as your editor. A palette entry is a reusable template; a block added to your canvas is an instruction in your program. The instructions do nothing until you press Run. If a program asks a question, it pauses in Terminal: type one answer and press Enter or Send to continue. Terminal then shows the next prompt or the program's output. Editing the program does not retroactively change a completed run.
Build with me · 1
Make the computer say one thing
Start with a tiny program whose result is easy to recognise. A program is a set of instructions for the computer. This first one has a single instruction: display a greeting. The blue block below is the same block you can edit in your practice editor, not a screenshot of another application.
Read the label from left to right: say, then the message to say. The white socket contains text. Text is a sequence of characters, including spaces and punctuation. At this point there is no model and nothing is being trained; you are learning how to give a precise instruction.
Choose Try this stage to put a copy in your editor. Press Run and look at Output. You can also build it yourself: choose Add blocks, find the Basics group, and add a say block. Click its white socket and enter the greeting. Do not type the word say into the socket; the block already supplies the instruction.
What to look for
Output contains Hello, Ada!. Editing the socket does not change an earlier result: press Run again after changing the program. If nothing prints, check that the block is on the canvas and belongs to the script rather than sitting loose inside an unconnected value socket.
Make it yours
Replace Ada with a made-up name, a pet's name, or a character you like. You do not need to provide your real name. Keep the greeting short enough that you can recognise exactly what changed when you run it.
Build with me · 2
Connect two instructions in order
A stack gives the computer an order. It performs the top statement, then the next statement underneath. A statement is an instruction that does something, such as displaying text or storing a value. Touching blocks form one connected program when their joints snap together.
Adding a second say block does not replace the first one. You now have two instructions and should expect two output lines. Predict which line comes first before you run. This habit makes it easier to notice an accidental gap or a block placed in the wrong position.
Add a second say block below the first. Drag its top joint toward the first block's bottom joint and release when the insertion indicator appears. The two blocks should form one stack. Use Try this stage if you want to compare your arrangement with a working copy; Undo restores your previous work.
What to look for
The greeting appears first and the learning message appears second. If the order is reversed, move the statements. If you typed both messages into one socket, the result is still one instruction, which is different from practising two connected steps.
Make it yours
Swap the two messages. Write down the order you expect, run, and compare. Then restore the greeting to the top. You changed program order without changing either message's text.
Build with me · 3
Store a name before displaying it
Now separate the data from the instruction that uses it. The set block creates a variable called name and gives it the text Ada. A variable is a name your program uses to refer to a stored value. You can choose another value while keeping the later instructions the same.
The rounded name block is a value block. It supplies the current value of name to the say block's socket. Typing the letters name into the socket instead would print the literal word name. The visual connection shows which value is being read.
Put set name to Ada first. Add the labelled say block below it. Type Hello into the label field, then insert the rounded name value into its value socket. Find name in the variable menu after its set block exists. Keep the set block above the first block that uses name.
What to look for
The program prints Hello Ada. The set statement itself produces no output; it stores information for a later instruction. If the output is Hello name, replace the literal socket text with the rounded name block.
Make it yours
Change only the text in the first set block. Run again. The greeting should use your new name without editing the say block. This is why keeping a reusable value under a name is useful.
Build with me · 4
Add an age as a number
Text and numbers have different jobs. A name is text, but an age used for arithmetic should be a number. In this block editor, entering an ordinary numeric value such as 12 in an any-value socket produces a number in the generated program.
Create a separate variable called age. It does not change name; each variable refers to its own value. The two labelled output blocks let you inspect both. Labels such as Hello and Age are text chosen for the person reading the output, not variables the computer looks up.
Add set age to 12 after the name assignment. Put an age value block into a labelled say block below the greeting. Run the whole stack from the top. All the values used later must first be created in this run.
What to look for
The two output lines contain your chosen name and age. There is no requirement to use a real age. If age prints as a word, inspect the socket; if it is missing from the menu, check the spelling in the set block.
Make it yours
Choose any whole-number age between 1 and 100 for your fictional character. Change the label from Age to Years old if you prefer. Explain which edit changes the stored data and which changes only how the result is described.
Build with me · 5
Use a value inside another calculation
A calculation can sit inside a set block's value socket. Here the plus block reads age and adds one. Its result is stored as next_age. The computer evaluates that inner calculation before completing the outer assignment.
The name next_age is one name containing an underscore, not two words separated by a space. It describes what the value means. We keep the original age so that the two output lines can show before and after together.
Build a plus value block with the age variable in the left socket and 1 in the right. Place the whole plus block inside set next_age to. Add an output line that reads next_age. Compare the nesting carefully: the value is inside the assignment, and the assignment is a statement in the main stack.
What to look for
With age 12, output shows Age 12 and Next birthday 13. If your character has a different age, the second number should be exactly one larger. Changing the input should change the result without editing the plus block.
Make it yours
Predict the result for an age of 19, then run it. Next, change the added amount from 1 to 5 and rename the output label to In five years. Explain why changing a label alone would not have changed the calculation.
Build with me · 6
Put a statement inside a loop
A loop repeats the statements placed inside its open body. This repeat block runs its body three times. The greeting is inside; the next-birthday output is below the loop and outside it. That placement determines how often each statement runs.
Follow the program in order. It stores name and age, calculates next_age once, enters the loop, prints the greeting three times, leaves the loop, and prints the final age once. A loop does not repeat every statement visually near it.
Add repeat from Control and set its count to 3. Move the greeting into the indented opening inside the repeat block. Keep Next birthday below the closing edge. If you load this stage, inspect the indentation before running rather than treating its output as a surprise.
What to look for
Three greeting lines appear, followed by one next-birthday line. If the age appears three times too, it is inside the loop. If the greeting appears once, it probably sits below the loop instead of inside its body.
Make it yours
Choose a small count between 2 and 5 and predict the number of output lines. Then move the birthday output into the loop and compare. Avoid very large counts while learning; a small visible result is easier to inspect.
Build with me · 7
Change the program, then recover your work
Editing is part of programming. You will move a block into the wrong place, delete a useful step, or try a change that does not help. Undo lets you return to an earlier source arrangement. It does not erase a fact from the world or turn back a completed training run; it changes the program you will run next.
This stage returns to the simpler personal greeting. Keeping a small working version makes mistakes easier to locate. Read each statement and say what it contributes before adding anything else.
Change the age, run, and observe the new result. Use Undo to restore the previous edit and run again. Use Redo to reapply it. The previous output remains visible until another run produces a result, so always connect your observation to the program version that actually ran.
What to look for
Undo and Redo change the program. Running the restored version reproduces its expected greeting and arithmetic. Loading a worked stage is also undoable, so it does not permanently replace an experiment you wanted to keep.
Make it yours
Create a deliberate mistake by replacing the rounded age value in an output socket with the text age. Predict the wrong output, confirm it, and then repair it. Explaining the mistake teaches more than copying a correct stack without reading it.
Build with me · 8
Change a value on each turn
A repeated change can build a result. Begin with total equal to zero. The change block reads the current total, adds three, and stores the new value under the same name. The repeat body performs that update five times.
Trace the stored value: before the loop it is 0; after the first turn it is 3; then 6, 9, 12, and finally 15. The set block is outside the loop. Inside, it would reset total to zero every turn, so the final value would be 3. Location changes meaning even when every individual block is valid.
Build the three outer statements shown. Drag change total by 3 into repeat's opening. Keep set total to 0 above repeat and the labelled output below it. Run and compare with the five-value trace.
What to look for
One output line says Total 15. The loop has five turns, but the output runs once because it follows the loop.
Make it yours
Choose a different small repeat count or amount, calculate the expected total, and run. Change one choice first so you can connect the result to the changed instruction.
Build with me · 9
Print inside the loop to inspect intermediate values
A temporary output statement is a debugging tool. Place it after change, inside the loop, to reveal the value each turn just stored. Keep the final output outside as well. The program now shows both the journey and the result.
Before change, the diagnostic output would show the old value: 0, 3, 6, 9, 12. After change, it shows 3, 6, 9, 12, 15. Both are correct descriptions of different moments. When debugging, ask not only which value you printed, but when you printed it.
Add a labelled output inside repeat immediately after change. Run. Use its Block actions menu to delete the diagnostic statement and Undo to restore it. Read whether the menu removes a block or its connected group before confirming.
What to look for
Five During the loop lines show 3, 6, 9, 12, 15. Finished shows 15 once. Removing diagnostic output changes what you observe, not the calculation.
Make it yours
Move the diagnostic output before change and predict all five lines. Restore it with Undo. Explain why the final result stays 15 although the intermediate messages differ.
Build with me · 10
See the same instructions written in Python
Choose View Python in your practice editor. The block program becomes ordinary Python text. set name to Ada becomes name = "Ada". The equals sign assigns a value to a name. Quotes identify text. The age assignment uses a number without quotes.
The nested addition becomes next_age = age + 1, and a labelled say block becomes a print call. You have already chosen the order, values, and operation. Python expresses those same choices with characters instead of connected shapes. Later lessons teach the punctuation and indentation you must supply when typing those instructions yourself.
Read the generated Python from top to bottom while comparing it with the blocks. Switch back to Blocks to edit this lesson's program. View Python is a view of that program, so its text changes when you change the blocks. Use Download practice code if you want to keep a source copy.
What to look for
Each set statement has a corresponding assignment, and each output statement has a corresponding print call. Your chosen name and age appear in the generated source. Viewing it does not run it or train anything.
Make it yours
Change the age or a greeting in Blocks, then look again at Python. Identify the exact line that changed. You do not need to memorise the whole language; start by recognising the instructions you already understand.
Recover a connection without starting over
Drag a block by its solid body rather than its editable fields. Aim at the insertion marker and release when the intended joint or socket is highlighted. A statement connects to a stack or a loop body; a rounded value fits a compatible value socket. Being close on the canvas is not the same as being connected.
Use the Block actions button for precise actions such as duplicating, detaching, or deleting. Read whether an action applies to one block or a connected group. Undo restores an accidental edit; Redo reapplies it. The canvas Bring everything back on screen button changes your view so distant blocks become visible. Panning and zooming affect the view, not execution order.
Keep your work
This lesson saves the program and text files in this browser. Each article has separate work, so trying another lesson does not replace this one. Terminal answers belong to the current run; run again to answer again. A saved program is a recipe: every Run executes it again from the beginning. Output and fitted models are runtime results, so keep useful measurements in your notes. Browser storage can be cleared; download your source if you need a separate copy. A Python download records the generated instructions, while a lesson-workspace backup preserves editable blocks.
The site also has a separate full-page Editor for bigger projects; you do not need it for any lesson in this level, because every lesson has its own editor beside the text. Your next task is to explain a program before running it: name the values it creates, point out which statements repeat, and predict the output.
Full reference solution
This is the complete worked program. Try building it yourself first, then use this reference to find the first place your version behaves differently. The Python below is generated from these exact blocks; helper functions are included so its behaviour can be inspected.
name = "Ada"age = 12next_age = (age + 1)print("Hello", name)print("Age", age)print("Next birthday", next_age)Compare this with your version. Different names and personal choices are fine when the program follows the same logic.
Keep your progress
Sign in and every reading, quiz, and exercise you finish is saved.