If - Else Statement (if-else)
Use for the scenario that has two decision-making only.
Usage
if meet_condition:
do action
else:
do fallback_action- The condition
mustreturn Boolean value. - If the first condition return
Truethan else will handle when condition returnFalse, or vice-versa.
Example
if-else.py
py
age = int(input("Please enter your age: "))
if (age >= 18):
print("You are eligible to play this game")
else:
print("You are not allowed to play this game")Results:
Trial 1: (age = 20)
You are eligible to play this gameTrial 2: (age = 10)
You are not allowed to play this game