A commented program with a constant
The last print shows that a # inside quotes is just text.
A comment is a note for human readers that Python ignores. Good code is mostly readable names, with comments explaining *why*. PEP 8 is Python's shared style guide (four-space indents, snake_case names, CAPITAL constants), and tools such as Ruff apply it automatically.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Rewrite this code in good style: r = 0.05, then m = 1000, then i = m * r, then print(i). Rename the variables so they say what they hold, make the rate a CAPITAL constant, and add two comments that explain why.
Write a program with a module docstring and print the docstring.
Rewrite A=5;B=A*2 in PEP 8 style on two lines with good names.
Explain it without notes
What makes a good comment, and what makes a bad one?
What is a docstring, and how is it different from a comment?
List four rules from PEP 8 and say why they matter.
What is the naming convention for variables, classes and constants in Python?
Expected output
Total with tax: 236.00
# this is inside a string, not a comment