Clear names
Python · Unit 19: Clean code
- Full plan
- Python
- 10 exercises
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. Multiple choice
This code charges three hotel nights with 10% off. Which names, instead of
a,bandc, read best?2. Find the bug
is_evenshould say whether the number is even. Which line has the error?3. Complete the code
has_passingmust say whether any grade reached 6. Complete it.4. Put the lines in order
Put the program in order. It prints the middle grade.
5. Predict the output
What does this code print?
6. Predict the output
What does this code print?
7. Find the bug
This program should print both totals. It crashes on line 5, but the error is earlier. On which line?
8. Complete the code
Complete the call to find out whether 7 is odd.
9. Predict the output
What does this code print?
10. Multiple choice
You read this line in someone else's program:
b = Ticket(3). Without seeing anything else, what does the capital inTickettell you?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.