Dungeon Coder


Conditional Love

If This, Then That

The only way you'll be known and loved by all as a hero of the ages is to do something spectacular. We say, then, that this love from fellow citizens is conditional. It depends on some condition being met. Maybe you have to slay some dragons, rescue some townsfolk, recover long lost treasure, or something of the sort.

This brings to mind the programming concept of conditional branching. Conditional branching is the way by which we give the computer instructions that should do one thing if one condition is met, or something else if the condition is not met.

For instance, imagine your local apothecary (potion brewer/merchant) is hiring cashiers. Knowing the laws such as they are, they must be sure that any potential hiree meet the minimum age requirements. We all know what happens to even the best craft potion brewers when they break such laws. So, employ conditional branching: if the applicant is old enough, they might qualify for the position. Otherwise, they must not be considered.

In the following python repl widget, we see the python syntax (rules of the python language) for making use of conditional branching (note: >= means greater than or equal to):


  1. How would you change the above code so that the applicant is old enough to cause the first condition to be true? 
  2. What would the output be if you changed the code so that applicantAge = 88?
  3. How might you change the code so that the minimum age would now be 21?
  4. Now, make the applicantAge high enough to meet the new minimum age requirement.
  5. What happens if you get rid of the = next to the >? How does that change the conditions?

Join the Dungeon Crawl: A place for programmers to ponder, partake, and peruse postulations pertaining to programming, politics, potions, and pizza.

If you subscribe on Patreon, you will be granted access to the Dojo, a growing collection of quality computer science classes created and actively mantained and frequented by the Dungeon Master!

Become a Patron!


Contact: dungeon_master@dungeoncoder.com