Mission Control sends the rubric for capstone projects. Rocket reads it and gulps. "Explains it? I have to explain my code?"
Raven holds up her notebook. "What do you notice about code you wrote last week? Do you remember why you wrote each line?"
"Um, mostly," says Rocket. "Not every line."
"So write notes in the code itself," Raven says.
Nova sparkles. "Here is a hint. Python skips any line that starts with a hash sign."
A comment starts with #. Python skips it. Comments explain why the code does something, for people who read it later.
# Part 3: what is running low?
def low_stock(stock, limit):
low = []
for item in stock:
# keep only supplies under the limit
if stock[item] < limit:
low.append(item)
# A to Z order makes the list easy to read
return sorted(low)
print(low_stock({"rope": 2, "water": 40, "lamps": 3}, 5)) Output: ['lamps', 'rope']
| Statement | True or false? |
|---|---|
| Python runs comment lines. | ? |
| A good comment can explain why the code does something. | ? |
| Comments change the output of the program. | ? |
The rubric has four areas. Each one can be getting started, got it or above and beyond.
| Area | Getting started | Got it | Above and beyond |
|---|---|---|---|
| Ideas | Names the project | Plan shows the parts, the data and who will use it | Plan changed after feedback from someone else |
| Code works | Some parts run | The whole program runs and the output is right | Adds a new feature that also works |
| Tests | One test | A test for each helper, all passing | Includes edge cases, like empty or missing items |
| Explains it | Reads the code aloud | Explains what each function does | Explains why a choice was made, like dictionary or list |
# Part 4: count the crew
def count_crew(node):
# every node counts itself
total = 1
# then add each smaller tree
for child in node["crew"]:
total = total + count_crew(child)
return total
team = {"name": "Bo", "crew": [
{"name": "Cy", "crew": []},
{"name": "Dee", "crew": []},
]}
print(count_crew(team)) | Statement | True or false? |
|---|---|
| Comments are for people who read the code. | ? |
| A comment line prints when the program runs. | ? |
| The rubric has four areas. | ? |
| Explaining why you chose a dictionary is Above and beyond. | ? |
Week 11 complete! You chose, decomposed, picked data, wrote tests and read the rubric. Next week we build and ship it.