LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.
Lesson 17: If elif else Statements In PythonIn Python if statement evaluates whether a condition is equal to true or false. The statement will execute a block of code if a specified condition is equal to true. Otherwise, the block of code within the if statement is not executed. Decision making is required when we want to execute a code only if a certain condition is satisfied. The if…elif…else statement is used in Python for decision making.
Example Code: If elif else Statements In Python.
The above program speifies the output given 3 conditions as under.
Condition 1. if age = 18
you are an adult.
you can vote.
Condition 2. age < 18 and age > 3
You are not eligible.
Condition 3. else
You are a child
print("thank you") is the common string for all the 3 given condition.
Now change the age variable in the code above and observe the output for different ages.
Condition 1 if: for age >= 18
Condition 2 elif: for age < 18 and age > 3
Condition 3 else: for any condition other than the above two situation.