← Back to course
Code Crew G5 / Week 11 / Friday
5/6
Week 11 Β· Plan your capstone

Friday

Comments and the rubric
// Choose, break it down, test it first
⏱ about 15 min

Friday: Comments and the rubric

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."

Comments

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']
StatementTrue or false?
Python runs comment lines.?
A good comment can explain why the code does something.?
Comments change the output of the program.?
WHY THIS EXERCISEComments are for people. They help you explain your choices.

The capstone rubric

The rubric has four areas. Each one can be getting started, got it or above and beyond.

AreaGetting startedGot itAbove and beyond
IdeasNames the projectPlan shows the parts, the data and who will use itPlan changed after feedback from someone else
Code worksSome parts runThe whole program runs and the output is rightAdds a new feature that also works
TestsOne testA test for each helper, all passingIncludes edge cases, like empty or missing items
Explains itReads the code aloudExplains what each function doesExplains why a choice was made, like dictionary or list
For a grown-up
Use this rubric next week as a conversation, not a grade. Ask your child to show you one test and explain one choice.
USE THE RUBRIC.
  • Read the question.
  • Tap your answer.
Every helper has a passing test, and one tests an empty dictionary. Which level is Tests?
You can say why you used a dictionary for supplies. Which level is Explains it?

Practice lab: read the comments

# 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))
How many comment lines are in the program?
What does the program print?
If every comment were deleted, what would it print?
What sign starts a comment?
RUBRIC CHECK
  • Read the question.
  • Tap your answer.
The program runs, the output is right, and a new feature also works. Which level is Code works?
A plan only names the project. Which level is Ideas?
Which comment explains why?
StatementTrue 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.?
WHY THIS EXERCISEClear comments help you explain your choices, which the rubric rewards.

Week 11 complete! You chose, decomposed, picked data, wrote tests and read the rubric. Next week we build and ship it.

← Thursday