- IF is the first conditional statement you will use
- It allows you to execute different code depending on the circumstances
- Look how the code is indented to identify it is part of the IF statement
#Declare variables
letter = "a"
#Check if letter is 'a'. If so, print message
if letter == "a":
print("The letter is a")
print("Indented lines are included!")
#Print this message anyway because there is no indent
print("This prints no matter what happens")
Tasks
- Type in the code above and make sure it works
- Modify the program to accept a character typed in by the user
- Modify the program to check for the letter ‘b’
- Save and label your code
Extension Task
If statements work with numbers too. Create an IF statement to check a number.