Skip to the content

Clear names

Python · Unit 19: Clean code

A name is the shortest explanation there is. With p = 3 you have to read the whole program to find out what p is.

The name says what it holds, not what type it is: days, not num1.

days = 5
price_day = 120
print(days * price_day)

Prints

600

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Multiple choice

    This code charges three hotel nights with 10% off. Which names, instead of a, b and c, read best?

  2. 2. Find the bug

    is_even should say whether the number is even. Which line has the error?

  3. 3. Complete the code

    has_passing must say whether any grade reached 6. Complete it.

  4. 4. Put the lines in order

    Put the program in order. It prints the middle grade.

  5. 5. Predict the output

    What does this code print?

  6. 6. Predict the output

    What does this code print?

  7. 7. Find the bug

    This program should print both totals. It crashes on line 5, but the error is earlier. On which line?

  8. 8. Complete the code

    Complete the call to find out whether 7 is odd.

  9. 9. Predict the output

    What does this code print?

  10. 10. Multiple choice

    You read this line in someone else's program: b = Ticket(3). Without seeing anything else, what does the capital in Ticket tell you?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →