Be Globally Certified In Python
What’s an if else statement:
An If Else statement is a conditional statement used in python to run a different set of statements if a condition is true or false
Example: When going to school you can check:
(Condition) if school bus is outside:
(Decision): Get in the bus
(Alternative) else (means if school bus is not around):
(Decision): Wait a bit
So this means when you check and the school bus is outside then you should hop in but if you can’t find bus yet, then you have to wait for it
Things to note:
1. Single equal sign = is used in python to assign a variable to it’s data value
english = 70
maths = 85
2. Double equal sign == is used in python to compare if two variables have the same data
if (maths == english)
3. The column : is used to start indentation after the if else conditional statement
if (nathan == 12):
4. Indentations are the spaces inside your conditions (if, else) to tell python the statements only runs if the condition is True
if (nathan == 12):
print”Nathan is ready for the python exam” (There is a space before the print, python knows it only runs if the condition is True)