The Thinking Behind Every Program

Why understanding a problem is more valuable than memorising Python syntax.

Introduction: The difficulty was not always Python

I have said quite a lot about my struggles when I began learning Python.  I could recognise instructions such as for, if, print() and .append(). I could even follow examples and build small programs with assistance.

But there was a more difficult question but also one that makes more sense. If problems are not human why attempt to solve it: Could I start with a human problem and independently decide which instructions were necessary?

Recognising code and designing code are different skills.

But approaching code from the perspective of what a human wants helped me to connect the human problem to the syntax. This discovery changed my approach to learning. Instead of asking, “Which Python instruction should I write first?”, I began asking, “What exactly does the human want to accomplish?”

That became the foundation of my Deep Understanding Roadmap.

1. Start with the human intention

An image of a workspace indicating what goes on before an idea comes to live.

Consider a simple request:

“Examine the files in my Downloads folder and identify the PDF files.”

Before writing Python, we can describe the journey in ordinary English:

  1. Locate the Downloads folder.
  2. Examine each item in the folder.
  3. Determine whether the item is a file.
  4. Check whether the extension is .pdf.
  5. Keep the information that satisfies the rule.
  6. Present the results.

The program is no longer an unexplained collection of commands. Each instruction has a responsibility.

This is the principle I call English → Logic → Code.

English identifies the problem. Logic establishes the necessary decisions and actions. Python expresses those decisions in executable form.

2. Understand what a variable actually does

A variable is a name associated with an object.

This does not mean count is permanently zero. It establishes the starting value.

Later:

Python evaluates the right-hand expression first, then assigns its result to the name on the left.

A useful mental model is:

LEFT SIDE ← RESULT OF RIGHT SIDE

This also explains why assignment and comparison must not be confused.

Assigns the value 5.

Asks whether the current value equals 5 and produces a Boolean result: True or False.

The same distinction applies when reading files, calculating totals and updating dictionaries.

3. The question determines the state we need

Not every problem requires the same kind of variable.

Suppose we ask:

“Does this folder contain at least one PDF?”

We need a yes-or-no answer:

found = False

But if we ask:

“How many PDF files are there?”

We need a counter:

If the question becomes:

“Which PDF files are there?”

We need a collection:

And if we ask:

“How many files belong to each extension?”

A dictionary may be appropriate:

This is an important design lesson: the human question determines the type of surviving state.

Choosing the correct state before writing a loop often makes the remaining program much easier to design.

4. Recognise the responsibilities of common data types

Python provides different structures because information has different shapes.

A string represents text:

An integer represents a whole number:

size = 2048

A Boolean represents a logical condition:

found = False

A list holds an ordered collection:

A tuple groups related values:

A dictionary associates keys with values:

file_sizes = {“report.pdf”: 2048}

A set is useful for unique values and membership checks:

The objective is not to memorise every operation available to each type. It is to understand what kind of information the program needs to represent.

For example, a filename and its size belong together, so a tuple can be useful. Several files belonging to one extension form a list. Several extension categories can be organised in a dictionary.

5. Functions turn repeated logic into reusable operations

A function receives information, performs a defined task and can return a result.

def human_size(size):

return f”{result:.2f} MB”

Calling:

Produces:

2.45 MB

The function receives 2450000, calculates a result and returns it to the calling instruction.

Our engineering description becomes:

RECEIVES → DOES → RETURNS

This is especially useful when a program grows. Instead of repeating the same calculation in several places, we give that calculation a clear name and reuse it.

A well-designed function should have a responsibility we can explain in one sentence.

6. Conditions express decisions, not actions by themselves

Consider:

The condition asks a question.

The indented instruction specifies what happens when the answer is True.

Python does not automatically collect or print anything merely because a condition is True. We must explicitly describe the required action.

This distinction becomes critical when writing filters, file searches and validation tools.

7. Build programs from the top down

Before implementing a practical tool, I now find it useful to create a small engineering card:

Human request: What problem are we solving?

Input: What information will the program receive?

Collection: What objects will it examine?

Rules: Which decisions must it make?

State: What information must survive the processing?

Output: What should the user receive?

Proof: How will we know the program worked?

For a File Analyzer, this might become:

  • Input: a folder path.
  • Collection: folder items.
  • Rules: process files and identify extensions.
  • State: total count and files grouped by extension.
  • Output: TXT, CSV and JSON reports.
  • Proof: compare the report with known files in a test folder.

This design approach reduces the temptation to copy code without understanding its purpose.

8. Errors can reveal gaps in the design

An error is not always evidence that the whole program is wrong.

For example:

will raise NameError if report_folder has not been defined in that execution.

The problem is not the print() function. The problem is that the name has not been assigned a value in the current program.

Likewise, trying to use .append() on a dictionary reveals a misunderstanding of the object type. Lists have .append(); dictionaries use keys to assign or retrieve values.

Understanding the type of the current object is often more useful than changing code randomly.

Conclusion: Programming begins before the first line

My most important discovery is that Python syntax becomes easier to understand when every instruction answers a clearly defined question.

The journey is:

Human intention → Plain-English procedure → Data structures → Decisions → Actions → Result

The long-term goal is not simply to write programs that run. It is to develop the ability to explain why each instruction exists, what information it receives and what changes after it executes.

That is the foundation of independent programming.

This post is part of my ongoing learning archive.
→ My Tech Learning Journey — One Step at a Time

No login needed to drop a comment — just drop your name and share your thoughts below 👇