By Kevin McAleer, 4 Minutes
Page last updated November 20, 2026

Robots have to decide things. Is the wall too close? Is the button pressed? In blocks and in Python, decisions are made with if.
Open Control. The if block has a pointed socket for a question and a mouth for the blocks to run when the answer is yes.

Questions come from the Logic drawer. The comparison block asks things like “is this equal to that?” or “is this less than that?”, and its answer is always True or False.
roll.You rolled in it, press its + and drop the roll variable into the new socket.roll = 6.You win! for the if, Try again for the else.
Run it a few times. The answer is in the console.
random.randint(1, 6) picks a whole number from 1 to 6if roll == 6: is the question. Notice the two equals signselse: is what happens when the answer is noThis catches everyone once. The block says =, but the Python says ==.
| Python | Means | Block |
|---|---|---|
roll = 6 |
Put 6 in the box called roll | set roll to 6 |
roll == 6 |
Is roll equal to 6? | roll = 6 (pointed) |
Blocks can use one symbol for both because the shape tells them apart. Python needs two different spellings.
The comparison block’s dropdown has six questions:
| Block | Python | True when |
|---|---|---|
| = | == |
Both sides are the same |
| ≠ | != |
They are different |
| < | < |
The left is smaller |
| ≤ | <= |
The left is smaller or the same |
| > | > |
The left is bigger |
| ≥ | >= |
The left is bigger or the same |
You can join questions with the and / or block, and flip one with not.
So close! for a 5.wins variable and count how many times you win in 10 rolls.Problem: The comparison block won’t fit in the print block. Solution: Put it in the if block’s pointed socket. Why: Pointed blocks are true-or-false answers, and they belong in question-shaped sockets.
Problem: I typed if roll = 6: in the code pane and got a SyntaxError.
Solution: Use == to compare.
Why: A single = stores a value. Python won’t let you do that inside a question.
Problem: It prints both messages. Solution: Make sure the second print is inside the else mouth, not underneath the if block. Why: Blocks under the if block run every time, whatever the answer was.
Quick quiz 1 of 3
Which Python asks “is roll equal to 6?”
Quick quiz 2 of 3
When do the blocks inside “else” run?
Quick quiz 3 of 3
What can random.randint(1, 6) give you?
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments