Sometimes you need a couple of conditions to be true before you select an outcome. You may need to be over 12 years old AND over 110cm tall to go down the Extreme track at the luge. You may need to be over 25 years old AND have held a full driving licence for more than 3 years to hire that car.
You can put multiple conditions into an if statement, though each must be a self-contained condition, eg
"You need to be at least 12 years old and at least 110cm tall to go on the Extreme Luge track."
if age >= 12 and height >=110:
or
"You need to be over 25 years old and have had a licence for more than 3 years to rent this car."
if age > 25 and licence_held > 3:
or
"Pick a number between 1 and 10."
if number >=1 and number <=10:
As in the above examples 'and' means that BOTH the conditions need to be true for the whole if statement to be true.
The first thing needs to be true AND the second thing needs to be true.
You can also use 'or' between the conditions. Or means that the whole statement is true if any one bit of it is true.
Suppose we want people who are under 12 years old or over 50 years old, we could use:
if age < 12 or age > 50:
If we want to select all the females and everyone over 20 years old we would use OR because the person can be female OR they can be over 20
if gender == "female" or age > 20:
Take care when translating from everyday English into logic, it doesn't always go smoothly.
If we wanted the people with blue eyes and the people with green eyes you might think we'd use
if eye_colour = "blue" and eye_colour = "green":
but we need to use OR because each person can have blue eyes or green eyes:
if eye_colour = "blue" or eye_colour = "green":
If you lose a game by losing your last life and you lose by running out of time you would use OR because you lose if your number of lives is 0 OR if your time left is 0
if lives == 0 or time_left == 0:
If And Or video 1 - Using multiple conditions in an if statement
If And Or video 2 - Using two different variables in one if statement