0%

Plan, Build, and Test Programs · practice

Use Pseudocode as a Map

Pseudocode is a plain-language outline of a program’s logic. It lets you settle the order of operations before Python punctuation and indentation ask for attention too.

For one quiz answer:

receive the given answer and expected answer
clean the given answer
clean the expected answer
if the given answer is empty, return "missing"
if the answers match, return "correct"
otherwise, return "incorrect"

This resembles code because it describes control flow, but pseudocode has no official syntax. The useful question is not “Will Python run this?” It is “Can I translate each step into code?”

Match detail to the problem

Too vague:

handle the answer

Too detailed for an early plan:

set cleaned_given to given.strip().lower()

Useful:

if the cleaned given answer is empty, return "missing"

The outline names the decision and result without getting lost in Python syntax.

One step should have one purpose

Break a larger job into visible actions:

clean the given answer
clean the expected answer
if the given answer is empty, return "missing"
if the answers match, return "correct"
otherwise, return "incorrect"

This exposes an important ordering decision: check for a missing answer before deciding whether two cleaned answers match.

Revise the plan when you learn something

Pseudocode is not a contract carved in stone. If a hand-worked example reveals a missing rule, update the outline before continuing. Erasing one line of a plan is much cheaper than untangling five lines of code built on the wrong assumption.

The plan should become clearer as your understanding improves.

Keep it close while implementing

You can write pseudocode as temporary Python comments:

# Clean the given answer.
# Clean the expected answer.
# Return missing for an empty given answer.
# Return correct when the answers match.
# Otherwise, return incorrect.

For this exercise, keep the pseudocode comments so you can compare the map with the finished code. In later programs, remove comments that merely repeat an obvious statement, but keep comments that explain a non-obvious decision.

Which pseudocode step gives both a specific condition and the result for that condition?

Task

Plan and implement answer_status(given, expected) with this contract:

  • clean both answers by removing surrounding whitespace and ignoring capitalization;

  • an empty cleaned given answer returns "missing";

  • matching cleaned answers return "correct";

  • every other answer returns "incorrect".

Before writing the Python , replace the five starter TODO comments with plain-language pseudocode for cleaning each answer and choosing among the three possible results. Keep those comments above the code they map. Then translate the map into the body.

Keep the prepared calls. The final output must be:

correct
incorrect
missing