New selection introduction written at 19,000 feet on an airplane!

Jack Morgan authored
revision e994392bbc38b7304adf784d8a3ec88ac2b6007f
year-11/selection
# Selection

> Add comic

When developing programs, there will often be situations where you will want to do something only if a particular condition is true. An example may be you want the program to calculate a different ticket price if an age is under 18. A condition is an exact specification resulting in a value which is unambiguously either true or false. We will now practices some example conditions.

1. 4340 is larger than 99
2.
3.
As we write computer programs, there will be plenty of situations where we want the computer to choose between different options for a specific reason. For example, we want the program to decide whether to charge for an adult ticket or a child one depending on a age. Or in a more serious scenario, whether to approve a large bank loan for a customer depending on existing financial performance. We can use a type of statements called selection statements to pick particular code.

TODO: Add comic of computer picking between two doors. "Which door do I take?"

When a computer needs to choose between several options, we must provide it with a statement to evaluate based on the current conditions. The statement either needs to be evaluated as true or false. Now this may sound complicated, but we do this all the time. An example would be if I say "I'll go to the beach if it's sunny" (this is the statement), and then I look outside and see it is snowing (this is the condition). I think to myself whether my statement is true or false based on the conditions, and in this case my statement is false so I choose to stay home and do programming. Everyday there are many scenarios that you encounter that could be represented with selection statements:

- Have I added enough milk into my cereal bowl?
- Am I late for the bus?
- Have I done all my chores?
- Do I have enough money to buy this ice cream?

These are pretty general examples, but these highlight a lot of the different components used in selection statements.

---

####Exercise: Scenarios and Situations

List three scenarios that you have come across today, and the outcome for these decisions. Example: I needed to decide whether I was late for the bus. If I wasn't late then I continued to the bus stop, however if I was then I asked Mum for a ride to school.

---

Let's think about selection statements in programming more professionally. The statements the computer needs to evaluate must either be true or false. The statement 17 is greater than 5 is true, there is no denying that. The value true or false can actually be stored in a variable, called a boolean varaiable and is written as "True" or "False". I will now start refering to the boolean values with a capital T or F so you know when I'm talking about this special value. For most of your selection statements, you will be using strings and numbers so lets look at a few different tools that you can use.

< and > - The greater and lesser than signs (if you forget which way they go, think of it as a crocodile mouth and it always points to the larger number)
<= and >= - These symbols are for greater than or equal to, and lesser than or equal to.
== - Equal to, to check if a number or a string is exactly equal to something. Remember one equal sign if for when you want to make a variable equal to something, but two equal signs is for when you want to check if something is equal to something.

Here are some examples so you can see them in action:

54 < 59 evaluates to True
"Apple" == "Banana" evaluates to False
4 >= 23 evaluates to False
9000 <= 9001 evaluates to True

TODO: Check if it's common practice to have the larger number on one side

---

####Exercise: Evaluation

Evaluate if the following statements are true or false, if you don't know the result write down what you think the answer could be.

1. 55 < 22
2. 34433 <= 34343
3. age = 16
age > 12
4. 0 >= 0
5. "Batman" == "batman"

---

## Selection types

TODO: Could be the place to describe that you can

### If statment



```python
if temperature > 32:
print("It is very warm today")
```

The first line is the

Python uses indentation to show what is

TODO: Spaces or tabs?


### Else statement



### Elif statement




### Statement block

TODO: Talk about combining multipe statements together.
Try and follow through a selection block with different values.
Try and create selection blocks from flowcharts