The Single Job
Back at the craft bench, Hoppy notices a tiny kind of mess: two raw badge names need the same cleanup, and the code is starting to repeat itself. Nothing is broken yet, but the job feels blurry. Is this function tied to one special badge, or is it supposed to help with any raw badge name?
This checkpoint is about one useful reflex: a function should usually take an input, do one main action, and hand back a result. Today that one job is very small. The function only needs to polish one raw badge name.
One function, one clear cleanup job
If the same cleanup steps appear more than once, that is often a sign to pull them into one tiny helper. Then the helper can accept one piece of input, do its one job, and return the cleaned result. The outside code stays simpler because it only needs to call the helper again with a different raw value.
raw_badge_one = " silver fern "
raw_badge_two = " ember ribbon "
def polish_badge_name(raw_name):
cleaned_name = raw_name.strip().title()
return cleaned_name
first_badge = polish_badge_name(raw_badge_one)
second_badge = polish_badge_name(raw_badge_two)
print("First badge:", first_badge)
print("Second badge:", second_badge)
Notice how narrow the responsibility is here. polish_badge_name() does not print the final screen, and it does not try to manage every badge at once. It receives one raw name, cleans it, and returns the polished version. Because that job is clear, the same function works for both badge names.
Repeated code is a clue that a tiny helper may be hiding there
Today is not about a giant refactor. It is just about noticing one small pattern: if you are writing the same cleanup move again and again, you may be looking at one helper function that has not been extracted yet. A clear helper usually has clearer input, clearer output, and less repeated code around it.
Change polish_badge_name so it accepts one raw badge name, instead of always reaching straight for raw_badge_one.
Build cleaned_name from that input with strip() and title(), then use return cleaned_name.
Call polish_badge_name(raw_badge_one) and polish_badge_name(raw_badge_two). This is the checkpoint feeling: one small function, one clear job, used more than once.
One job does not mean “only one line.” It means one clear responsibility. In this lesson, the responsibility is simple: receive one raw badge name, clean it, and hand the cleaned name back.
Suggested SolutionExpandCollapse
raw_badge_one = " moss lantern "
raw_badge_two = " silver fern "
def polish_badge_name(raw_name):
cleaned_name = raw_name.strip().title()
return cleaned_name
first_badge = polish_badge_name(raw_badge_one)
second_badge = polish_badge_name(raw_badge_two)
print("First badge:", first_badge)
print("Second badge:", second_badge)Advanced TipsWant more? Click to expandClick to collapse
This checkpoint stays intentionally small. We are not talking about software architecture, and we are not turning this into a big cleanup project. We are only strengthening one habit: make a helper function's input, main action, and output easier to see.
That habit matters because later code gets easier to assemble when the small pieces have clear jobs. For now, one tiny badge-polishing helper is enough.