STR Coding Club logo STR Coding ClubLearn to code, together
Python and Practice

How to Turn One Python Exercise Into Four Harder Ones

One of our club members, fourteen, worked through 63 exercises on a practice site over about five months. Every one of them green and ticked.

A whiteboard listing four harder versions of one Python exercise beside a laptop with a short vowel counting function

One of our club members, fourteen, worked through 63 exercises on a practice site over about five months. Every one of them green and ticked. Then we asked the group to write a program that read a text file of club attendance and printed who had missed three sessions in a row, and she sat looking at a blank editor for eleven minutes. She knew every piece she needed. She had never once decided for herself which pieces to use.

I have watched that happen often enough now that I changed how our Tuesday sessions run. We do fewer exercises and we do more with each one. A single problem that takes a beginner twelve minutes to solve can carry a full hour of real practice if you know how to extend it, and the extending is where the thinking lives. This is the method I teach our volunteer mentors, with the exact problem we use to teach it.

Why finishing exercises stops teaching you

A practice exercise arrives pre decomposed. Somebody has already decided that this problem is about dictionaries, that the input is a list of strings, and that the answer is a single number. All that is left for you is to recall the syntax. That is a real skill and it is maybe a fifth of programming.

The thing a beginner cannot do after sixty exercises is look at a vague task and cut it into pieces. You can only practice cutting when the problem has not already been cut, and the cheapest way to get an uncut problem is to take one you have already solved and move the edges.

There is a second gain that surprised me. Extending a problem you solved ten minutes ago means you already understand the domain, so all your attention goes to the new difficulty. Starting a fresh problem spends the first five minutes just reading and re understanding, which is why six fresh exercises teach less than one exercise taken four steps further.

The four ways I extend a problem

We start with a problem any beginner can finish: count how many vowels are in a word. Five lines with a loop and an if, maybe three lines if the learner has met sum. Then we climb.

  1. Add a constraint. Same problem, but you may not use the in operator. Then: same problem, no if statement anywhere. Then: one pass over the word and no extra list. Each constraint forces a tool the learner owns but never reaches for, and the last one quietly introduces why dict lookups exist.
  2. Invert it. Now write the function that goes the other way: given a count, build any word that has exactly that many vowels. Inversion is the step that catches sloppy definitions, because the learner has to decide whether y counts, what happens with an empty string, and whether uppercase matters. Half our group discovers their original answer was wrong here.
  3. Scale it. Make it work on a file of 90,000 words instead of one word, then print the five words with the highest vowel ratio. Suddenly the shape of the data matters, reading a file matters, and sorting by a computed value matters. This rung is where sorted with a key argument stops being a trick from a tutorial and becomes the obvious thing to use.
  4. Generalise it. Replace vowels with a set of characters passed in as an argument, so the same function can count digits, punctuation or any alphabet the caller chooses. Then ask for a version that counts any condition at all, which means passing a function as an argument, and the learner has walked into higher order functions without anybody announcing them.

Four rungs, one problem, and the fourth rung is genuinely a topic from a second year course. Nobody had to be told they were ready for it.

Why more exercises is the wrong instinct

The standard advice is volume. Solve a hundred problems, solve one a day, keep a streak. I ran our club that way for a term and a half, so I am arguing with my own past practice here.

Volume produces a specific kind of learner: fast at recognising problem types, helpless when the type is unfamiliar. Our streak kids could write a list comprehension in nine seconds and could not plan a program with three functions in it. The pattern was consistent enough across about twenty members that I stopped treating it as a coincidence.

The opposite advice, that beginners should skip exercises and go straight to building projects, has the reverse failure and I like it even less. A fourteen year old who starts a game project after three weeks of Python spends four sessions fighting an installation problem and loses interest. Our abandonment rate on self chosen projects, before we changed anything, was somewhere around half.

Extending an exercise sits between the two. The problem stays small enough to finish inside a session, which protects motivation, and the extensions supply the planning practice a project would have given. I would not claim this is the only way to bridge the gap, and I am fairly confident it is better than either extreme on its own. We still do fresh problems, roughly one new problem for every three or four extensions.

What an hour actually looks like

Here is a real session, timings from my own notes rather than a plan. Base problem on the board at 18:05, most of the group finished by 18:17, with two still working and one mentor sitting beside them.

At 18:20 we gave the no if constraint. This took longer than I expected, about fourteen minutes, and produced three different approaches: a dictionary of counts, str.count called in a loop, and one learner who used filter after finding it in the documentation. We spent five minutes comparing them out loud, which is the part I would not cut if the session overran.

At 18:40 the file version. Nobody finished this inside the session and that was fine, because the first fifteen minutes of the next week started with it. The point of ending on an unfinished rung is that the learner goes home with a problem still open, and three of them had solved it before Tuesday without anybody asking.

If a learner stalls completely on a rung, drop back one rung rather than explaining the answer. A rung that is too high looks exactly like a learner who is stuck, and the getting unstuck approach only works when the gap is small enough to cross.

Running this with a mixed group

The reason I use this at club rather than just recommending it to individuals is that it solves the mixed ability problem almost by accident. Everyone gets the same base problem, so nobody is visibly on the easy worksheet. The fast learners are on rung three while others are still finishing rung one, and because it is the same problem the conversation across the room stays shared.

Two practical notes. Write the rungs on the board in advance so learners can climb without waiting for you, which removes the bottleneck of a mentor having to issue each next step. And keep the base problem genuinely easy, easier than you think it should be, because a hard base problem means your strongest learners never reach the interesting rungs and your weakest never start.

For solo practice the same ladder works with one change: write your four extensions down before you solve the base problem, so you are not tempted to declare it finished. This pairs well with a small daily exercise habit, and the rest of the Python and practice notes have plenty of base problems worth climbing.

FAQ

How do I know when a problem is used up?

When the next extension you can think of needs a concept you have not met at all. A rung that requires classes when the learner has not seen a class is not practice, it is a new lesson wearing a disguise. Move to a fresh problem and come back to this one later.

Does this work for a complete beginner in week one?

The constraint rung does, and the others mostly do not. In the first few weeks I use two rungs only, the base problem and one constraint, because the vocabulary is too small for inversion or generalisation to lead anywhere. Add the higher rungs around the point where the learner can write a loop without copying one.

Should learners look at other people's solutions?

Yes, after they have solved it, and specifically after they have solved the same problem twice at different rungs. Reading a solution before you have struggled teaches you what good code looks like without teaching you how anybody got there, which is a trade worth making only when you are properly stuck.

How many problems should a club keep in rotation?

We use about eight, all small, and reuse them across a term with different rungs. Fewer problems means mentors know them deeply and can spot a wrong turn in seconds, and repetition at a higher rung feels like progress rather than revision.

IA
Imogen Achebe

Imogen started a coding club at her school and now trains volunteer mentors. She writes about first steps in coding and projects that work for groups of mixed ability.

More posts by Imogen

More in Python and Practice