School supplies
"Mia, math" on a notebook tells whose it is and what it is for.
11CLEAN CODE · NAMES
A box's name should say what it keeps, so anyone can read your code.
IN REAL LIFE
A good label tells you what is inside before you open it.
"Mia, math" on a notebook tells whose it is and what it is for.
"Grandma" is much easier to find than "Contact 7".
Signs like "Fruit" and "Bread" help you find things fast.
LOOK FIRST
apples beats a, x or thing. You know what is inside without guessing.
Use lowercase words joined with _, like total_score.
No number at the start, no spaces. And score and Score are two different boxes.
LOOK FIRST
Each name tells you what it keeps or what it does.
apples = 5A box called apples. You can tell it keeps apples.pears = 3Another clear name: pears.total_fruit = apples + pearsTwo words joined with _. It keeps 8.def make_juice(fruit):A function name starts with a verb: it says what it does.RUN IT
Guess first. Then run real Python and check.
player_name = "Mia"
total_score = 10 + 5
print(player_name, "has", total_score, "points")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: Rename total_score to points. Change it in both places, then run again.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Which label is the best name?
Which name is best?
Which name follows Python style?
score2 = 10
2score = 10
score_2 = 10Which line makes Python stop with an error?
my pet = "Rex"SyntaxError: invalid syntax
How do you fix it?
score = 5
Score = 9
print(score)What will Python show?
Which name is best for it?
There are 3 cats and 8 dogs, but the boxes a and b got mixed up. Give them clear names and match the goal.
Cats: 3 Dogs: 8OUTPUT
Want a fresh start? Clear only this page.
Name each box for what it keeps, in lowercase with _. Start function names with a verb.