I want to get my students to exercise the conditional-branching mind-muscle. [edit: and I need it to be fun/playful]

I will ask them to read pseudo-code, then represent as a branching sketch[^1]. And vice-versa, go from illustration[^2] to pseudo-code. Then of course coding practice.

I wonder whether other teachers have found preferred[^3] conditional-branching exercising scenarios. For "scenarios" I mean the stage-setting one does for an exercise to have meaning or sense beyond the pure technical ability. Real life scenarios are ok but magic fungi that split in half and multiply by two are also ok.

Do you know any good conditional-branching exercising scenarios? [^4]

I'm right now thinking for a second class' homework. My students at this point are just familiar with assignment, ints strings and floats, and printing and reading input... but of course I'm curious about any other that might have come to your mind. Third class is lists and loops. Language is python. This line is mostly anecdotic but could be relevant.

Sincere thanks Let in the poetry I'm happy about finding this sx

## 3/1 Update

I am now thoroughly convinced that while loops fall into this class, as they are clearly conditional branching. In a longer course they might take a class on themselves, but since I've got eight classes I'd rather include them in this one and take the next one on for loops and lists than simple-mindedly slicing "loops" into its own class, as I feel somewhat inadequate to state that "there are two kinds of loops..." as I often read or hear. This opens a lot of room for creative exercise scenarios. For instance offering a recurring menu could lead to fun name-composing. Btw my students are high-schoolers mostly.

[^1]: (with no enforced appearance conditions, like the non-cute rhombus and whatnot)

[^2]: (patiently drawn by the writer)

[^3]: ("my lil battle horse")

[^4]: (I hope you'll spare me asking subjective, since I come with so much joy for my students and passion for the trade)

  • $\begingroup$ Have you considered implementing Fizz Buzz? I have heard stories (possibly apocryphal) that some Silicon Valley companies use this as a quick check of an interview candidates' basic programming skills. Supposedly (!) more people struggle with this than one might naively assume. $\endgroup$
    – njuffa
    Commented Nov 20, 2021 at 23:27
  • $\begingroup$ Thank you this is a good one definitely $\endgroup$
    – Vladimir
    Commented Nov 22, 2021 at 1:54
  • $\begingroup$ This brings nim to mind, perhaps for the quickests $\endgroup$
    – Vladimir
    Commented Nov 22, 2021 at 1:57
  • $\begingroup$ Are use programming in assembler/machine code? If so, then in the implementation of a counting loop repeat n times: $\endgroup$ Commented Dec 17, 2021 at 22:33

1 Answer 1


There are literally zillions of scenarios. Even before the loops are introduced. For example,

  • Min, max, and clipping a value into an interval.
  • Figure out whether a year is a leap one.
  • Determine if a Queen attacks a given square.
  • Solve the quadratic equation in reals (if det < 0:).
  • Calculate the value of a blackjack hand (an ace could be 1 or 11, your choice - just don't get busted if possible).
  • Find the counterfeit coin with balance scales (you know those puzzles)
  • Describe how to diagnose a network outage (is it the problem with your PC, the router, the ISP, the backbone. or is it an Armageddon already?).

The last two are nice examples of a problem where the flowchart is more relevant than the code.

  • $\begingroup$ Thanks! These are good. The quadratic equation will blend right in with our previous exercises. $\endgroup$
    – Vladimir
    Commented Nov 30, 2021 at 13:56
  • $\begingroup$ @Vladimir If you decide to use solving a quadratic equation as an example, I would suggest to make sure to introduce the numerically advantageous way (e.g. along the lines of what I outlined here, so as not to proliferate bad practices that one later finds deployed in real-life code. The other proposed exercises do not seem to carry such risk. $\endgroup$
    – njuffa
    Commented Dec 2, 2021 at 8:44
  • $\begingroup$ Hi! They are mostly high-school so I'm first concerned about simple formula-code translation, grasping the intuition... I will mention that there are some quirks around floating points though. The previous exercise might be for example coding pythagoras theorem, prompting for whether one is looking for a hypotenuse or a hick. $\endgroup$
    – Vladimir
    Commented Dec 3, 2021 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.