Free course · Lesson 5 of 5
Problem Solving with Python
In this lesson you will
- Break a small problem into steps
- Combine loops, conditions and data structures
Real problem-solving means combining everything above: variables, conditions, loops, functions, and data structures, applied to a task that actually matters. Start by breaking the problem into small steps, then write one function per step.
- Read the requirement carefully before writing any code.
- List the inputs you have and the output you need.
- Write pseudocode (plain-English steps) before real code for anything non-trivial.
- Test with small, simple data first, then with edge cases (empty list, zero, negative numbers).
💡 Practical Skill: This is exactly how a small business or NGO's first internal tool gets built — one working script that saves hours of manual spreadsheet work every week.
inventory = {"exercise books": 120, "pens": 45, "chalk boxes": 8}reorder_threshold = 10 def check_stock(inventory, threshold): low_stock = [] for item, quantity in inventory.items(): if quantity < threshold: low_stock.append(item) return low_stock items_to_reorder = check_stock(inventory, reorder_threshold) if items_to_reorder: print("Reorder needed for:", ", ".join(items_to_reorder))else: print("All stock levels are healthy.")
Practice exercise
Extend the inventory example so it also prints the total value of all stock.
Key takeaways
- Plan the steps in plain language before coding
- Test with normal and awkward inputs
- Small, named functions make programs easier to fix
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.