![]() |
| Python Conditional Statements|(if,if-else,elif) with Example |
Python Conditional Statements Definition
Conditional Statement in Python: A conditional statement can be using decision making control system. It can be used condition are satisfied or not satisfied. If the given condition are true and given condition are false than return compiler are false. Conditional statements in python are used to perform different actions based on whether a certain condition is true or false. They allow you to control the flow of your program by executing specific blocks of code depending on the your program conditions. The most common conditional statements in Python are `if`, `elif`, and `else`.
If Statement: This statement is used to test a condition. If the condition evaluates to true, the block of code inside the `if` statement is executed.
Elif Statement: This stands for "else if" and is used to test multiple conditions. If the first `if` condition is false the program checks the `elif` condition. If it is true the individual block of code is executed.
Else Statement: This statement is used to execute a block of code when if conditions is false than execute else.
Types of Decision Making in Management
- If Statement in Python
- If-Else Statement in Python
- Elif Statement in Python
- Nested If Statement in Python
Decision Making With If Statement
Syntax of If Statement in Python
Statements; |
Explain If Statement in Python
if age>=18: print("Your age is 18 this statement are executed"); |
Example of If Statement in Python
if age>=18: print("Your Age 18 You can derive a car") ============OUTPUT============ Enter Your Age:18 Your Age 18 You can derive a car |
Check Given No is Positive or Negative in Python
if n>0: print("You entered a Positive Number:",n) if n<0: print("You entered a Negative Number:",n) if n==0: print("You entered Zero:",n) ============OUTPUT============ Enter any Number:18 Your Age 18 You can derive a car |
Definition of If Else Statement in Python
Syntax of If Else Statement in Python
Statements else: Statements |
Explain If Else Statement With Syntax
if age>=17: print("Your age is 18 this statement are executed") else: print("Your age is less than 18 this statement are executed") |
Example of If Else Statement in Python
if age>=18: print("Your Age 18 You can derive a car") else: print("Your Age is below 18 You can not derive a car") ============OUTPUT============ Enter Your Age:17 Your Age is below 18 You can not derive a car |
Definition of If Elif Else Statement in Python
Syntax of Else If Ladder in Python
# Code to execute if condition1 is True else if condition2: # Code to execute if condition2 is True else if condition3: # Code to execute if condition3 is True else: # Code to execute if none of the above conditions are True |
Explain Else If Statement With Syntax
if age>=18: cout<<"Condition A Execute"; else if(Condition B): cout<<"Condition B Execute"; else if(Condition C): cout<<"Condition C Execute"; else: print("if not matched Condition Than Execute Else") |
Example of Else If Ladder in Python
if per<=100 and per>=80: print("You have A+ Grade") elif per<80 and per>=60: print("You have A Grade") elif per<60 and per>=50: print("You have B Grade") elif per<50 and per>=35: print("You have C Grade") else: print("You are Fail") ============OUTPUT============ Enter Your Percentage:61 You have A Grade |
Nested If Definition in Python
Syntax of Nested If in Python
Statements if condition 2: Statements if condition 3: Statements |
Explain Nested If Statement With Syntax
statements if(x>y): statements |
Nested if Program in Python
b=int(input("Enter b number: ")) c=int(input("Enter c number: ")) if a>b: if a>c: print("Number a is Largest: ",a) if b>a: if b>c: print("Number a is Largest: ",b) if c>a: if c>b: print("Number a is Largest: ",c) ============OUTPUT============ Enter a number: 30 Enter b number: 50 Enter c number: 20 Number b is Largest: 50 |
Nested if Program Example in Python
if n > 0: print("The number is positive.") if n % 2 == 0: print("The number is also even.") else: print("The number is odd.") elif n < 0: print("The number is negative.") if n % 2 == 0: print("The number is also even.") else: print("The number is odd.") else: print("The number is zero.") check_number(10) ============OUTPUT============ The number is positive. The number is also even. |

