Home » Chapter 3
Decisions
Decisions in programming allow us to change the behavior of our programs based on one or more conditions. In English we can express this concept with something like: if this then that. Here are a few conditional constructions written in English:
If today is Saturday or Sunday, then it is the weekend.
If I have enough money, I can buy that coat.
If you guess the right number, you win the game.
These are decisions based on conditions. The first one, for instance, answers the question Is this the weekend?. Well, it is the weekend if today is either Saturday or Sunday. In Python, we have several approaches available to us to create conditional decisions in our code. When we use these approaches we can have our programs behave differently based on those conditions, which is useful in many types of applications. This chapter outlines the primary approaches to handle decisions in Python.