So far everything we have done has been basic sequencing. What I mean is, 1 line of code is decoded and then the next and then the next.

We need computers to be able to make decisions based on the criteria we give them. This is paramount to everything computing. eg.

How it works

if something is True
		execute some code
else
		execute some other code 

<aside> πŸ’‘ Remember how before everything in Computing evaluates to True or False?

</aside>

Comparative Operators

Operator Meaning
> More than
< Less than
>= More than or equal to
<= Less than or equal to
== equal to
!= Not equal to

Example comparisons

You may remember seeing these Boolean expressions on the 3 - Math page

4 == 2+2 β†’ True

10 > 2+2 β†’ True

2 != 1+1+1 β†’ True

5 < 0 β†’ False

2 == 1+1+1 β†’ False

12 <= 7+7 β†’ True

If statement example

https://replit.com/@bitFez/ex15#main.py

This example compares 2 objects. water_temp and 100. They are both integers.

When the If statement compares the value of water_temp (which is 70) with the value 100, it checks to see if it is True that 70 is less than 100. πŸ’‘ Remember this is a Boolean expression.

Anatomy of an If statement

if statements.png

https://youtube.com/shorts/ux241ATdK5Q?si=Mk7yOzMLv0No-plL

Tasks

<aside> πŸ˜‘ Don’t think about skipping this part. This is tedious but you need to practice to get good and build muscle memory. Do each exercise below, typing each one out diligently 😊

</aside>

Extra tasks