liveBook · Manning

Problem definition

As explained in Get Programming: Learn to code with Python

A description of the task a program is expected to accomplish, including relevant inputs, interactions, and outputs.

A problem definition says what a program should accomplish, not necessarily how to code it. Look for the task, the inputs, the expected output, and any behavior that changes with the situation. If the steps are missing, you must work them out. section 12.1 section 2.5

From a vague request to a useful one

“Bake a loaf of bread” leaves many recipes open. Asking for a two-pound rosemary loaf and specifying ingredient amounts narrows the task, though you still need to decide how much rosemary to use and how to combine the ingredients. A programming request can leave similar decisions to you. section 2.2

Before writing code, treat the proposed program as a black box: what goes in, what comes out, and what should happen in special cases? Write a few sample inputs beside their expected outputs. A sketch can make the interactions easier to see; pseudocode can then turn the sketch into possible steps. section 2.3 section 12.1

Figure 2.4. A black box visualization of baking a loaf of bread with a given set of ingredients.

Use the bread-machine black box to separate given ingredients from the result before deciding on recipe steps. section 2.3

Quick check: two names in, one mashup out

Suppose a user enters two full names. The program separates first and last names, mashes up each pair, and displays the new name. Before coding, sketch that path and try short, long, odd-length, and even-length names as test inputs. Which cases might need special handling? section 12.1

Once the task is clear, divide it into smaller pieces of code. Test each piece against your examples, debug what fails, and repeat. Understanding the problem first makes those divisions easier to find. section 19.3 section 2.5

How Get Programming: Learn to code with Python covers it

How deep it goes
Gives a planning checklist and walks through sketches, sample cases, and pseudocode; leaves implementation steps to be worked out.
Examples
Uses bread requests of varying specificity and a two-name mashup with varied test inputs.
What it assumes
Begins with a familiar bread recipe and introduces implementation as the way code solves a task.
What you can do after
Practice/perform it by sketching inputs and outputs, choosing test cases, and dividing a task before coding.
How it connects
Connects problem definitions to black-box visualization, flowcharts, pseudocode, test cases, and debugging.

Also explained in

Compare how 6 books explain problem definition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.