Introduction to Problem Solving
Do not treat a program as something to copy mechanically. Try to solve the problem yourself first, then ask smart questions when you need help.
Begin with the Problem
Writing a Python program is not only a matter of producing instructions. It is also an exercise in problem solving. You begin with a problem, think about how it could be solved, and then create a Python program or script that expresses the solution. The more programs you create yourself, the more comfortable you become with both Python and problem-solving.
Do not treat a program as something to copy mechanically. Try to solve the problem yourself first, then ask smart questions when you need help.
Trace the Solution Path
The diagram is a practical learning path rather than a complete list of every stage that might appear in a programming project. Its central idea is that a program is the result of thinking about a problem. An algorithm provides a general process for solving a category of problems, and a Python program or script is created from that problem-solving work.
Use Algorithms as Plans
An algorithm is a general process for solving a category of problems.
An algorithm helps separate the solving idea from the final program. Before focusing on Python instructions, you can think about the general process that would solve the problem. That process can then guide the creation of a Python program or script. This way of thinking is useful because the goal is not merely to produce lines of code; the goal is to produce a solution to a problem.
Plan a Small Program
Turning a Small Task into a Program Plan
Imagine that you want to create a small Python program for a task you have chosen yourself.
- 1State the task
Describe what the program should solve before thinking about individual Python instructions.
- 2Try first
Make your own attempt to work out the solution. This gives you a clearer understanding of what you know and where you need help.
- 3Ask a smart question
If part of the task is unclear, ask about that specific difficulty instead of immediately asking someone else to solve the entire problem.
- 4Describe the algorithm
Write down the general process that could solve this category of problem.
- 5Create the script
Use the algorithm as a guide while creating the Python program or script.
- 6Split it if it grows
If the program becomes large, divide it into smaller pieces so there is less to look at while solving a problem, fixing a bug, or adding a new feature.
The finished program is connected to a deliberate problem-solving process instead of being an unexplained collection of instructions.
This example does not prescribe one universal algorithm for every task. It demonstrates how a learner can move from a problem to an attempted solution, a clearer question, an algorithm, and finally a Python program or script.
Control Complexity with Smaller Pieces
Large programs create a special problem: it becomes impossible to keep the entire program in your mind at the same time. The source material describes programs that may grow to millions of lines and explains why code should be easy to understand. Breaking a large program into multiple smaller pieces gives you less to look at when solving a problem, fixing a bug, or adding a new feature.
One very large program with every part considered at once
More of the program must be considered at the same time.
A program divided into multiple smaller pieces
Less of the program needs to be considered for a particular task.
Breaking a program into smaller pieces is not only useful when first solving a problem. It also helps when fixing a bug or adding a new feature.
Mistakes to Avoid
Common mistake Looking for a solution before trying the problem yourself
What it looks likeImmediately copying a solution without first deciding how you would approach the task.
Why it failsYou lose an opportunity to become comfortable with Python and problem-solving.
Do this insteadMake a genuine attempt first, then ask a focused question about the part that remains unclear.
Common mistake Asking a vague question
What it looks likeAsking for the entire problem to be solved without identifying the difficulty.
Why it failsThe question does not show which part of the problem needs clarification.
Do this insteadAsk a smart question about the specific step or idea that is causing difficulty.
Common mistake Treating a large program as one indivisible object
What it looks likeTrying to keep every part of a very large program in mind while changing one feature.
Why it failsAs programs grow, it becomes increasingly difficult to keep the entire program in your mind at the same time.
Do this insteadBreak the program into multiple smaller pieces.
Common mistake Focusing only on writing code
What it looks likeStarting with Python instructions without first considering the problem-solving process.
Why it failsThe program can become disconnected from a clear solution to the problem.
Do this insteadThink about the problem and its general solving process before creating the Python program or script.
Apply the Process
Choose a small program that you would like to create. Write down the problem it should solve, describe your first attempt, record one smart question you might ask, and outline the algorithm as a general process. Then decide whether the program would need to be divided into smaller pieces as it grows.
Hints
- Keep the chosen task small enough to describe clearly.
- Describe the solving process rather than writing Python code.
- Think about what would become difficult if the program became much larger.
Remember the Method
- 1Creating a Python program or script is part of a broader problem-solving process.
- 2An algorithm is a general process for solving a category of problems.
- 3Try to solve a problem yourself before asking for help, and ask smart questions when help is needed.
- 4As programs become large, break them into smaller pieces so they are easier to understand, modify, and debug.
- 5Creating your own programs helps you become more comfortable with Python and problem-solving.
Key Takeaways
- A Python program is the result of solving a problem, not merely writing instructions.
- An algorithm describes a general process for solving a category of problems.
- Independent effort followed by focused questions strengthens problem-solving practice.
- Breaking large programs into smaller pieces makes problems, bugs, and new features easier to handle.