Add to it
score += 1 means the same as score = score + 1.
02CHANGE + MATH
A box can take its own value, change it, and keep the new one. That is how games count points.
USE THE OLD VALUE
score = score + 1 looks strange. Python first works out the right side: the old score plus 1. Then it puts the answer back in the same box.
score = 3→score = score + 1→3 + 1 is 4. Now the box keeps 4.
THE SHORT WAY
score += 1 means the same as score = score + 1.
lives -= 1 takes one life away from the box.
score = 0 throws the old value away and puts in 0.
MATH WITH BOXES
apples = 4 and pears = 3. Python opens both boxes and uses the numbers inside.
apples + pears is 7.
apples - pears is 1.
apples * 2 is 8. The star means times.
apples / 2 is 2.0. Dividing always gives a decimal.
JOIN TEXT
Let's go slowly, one small step at a time.
Quotes tell Python: this is text, keep it just as it is.
Python puts the second piece right after the first one, like train cars.
You choose the space. Put it inside the quotes.
name has no quotes, so Python opens the box and uses what is inside.
name→Hi AnaPython opens the boxSame + sign, different job.
RUN IT
Guess first. Then run real Python and check.
score = 3
score = score + 1
print(score)What will Python show?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change + 1 to + 10. Then try the short way: score += 10.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
stars = 5
stars = stars + 2
print(stars)What will Python show?
coins = coins + 1Which line does the same job?
lives = 3
lives -= 1
print(lives)What will Python show?
steps = 2
steps = steps * 3
print(steps)What will Python show?
apples = 4
pears = 3
print(apples + pears)What will Python show?
name = "Ana"
print("Hi " + name)What will Python show?
print("Hi" + "Ana")What will Python show?
print("2" + "3")What will Python show?
PyBot found a star, but its score is still 0. Fix the middle line so the box keeps the new score.
1OUTPUT
Want a fresh start? Clear only this page.
score = score + 1 adds one. Next, PyBot meets every math sign.