Decision making statement contain conditions that are evaluated by the program. If the condition is true, then a set of statements are executed and if the condition is false then another set of statements is executed.

In python decision making is performed by following statement.


  • If statement 
  • If - else statement
  • Nested If statement


Indentation:


        In other programming languages indentation is not important but in python indentation is very important. Python uses indentation for blocks, instead of curly braces.

Eg:

a=20
b=90
if a<b:
 print("A is smaller")

OUTPUT:

A is smaller

1. If Statement


An if statement is a programming conditional statement that, if proved true, performs a function or displays information.


Eg:

a=20
b=10
if a>b:
 print("A is greater than B")

OUTPUT:

A is greater than B


2. If - Else Statement


An if else statement is a conditional statement that runs a different set of statements depending on whether an expression is true or false. If the statement is true the first statement will be executed if the condition is false the else part will execute.


Eg:

age=int(input("Enter your age?"))
if age>=18:
 print("You are eligible to vote:")
else:
 print("Your are not eligible to vote:")

OUTPUT:

Enter your age?20
You are eligible to vote:


3. Nested If statement


The nested if statement allows us to check multiple conditions and execute the specific block of statements depending upon the condition.


Eg:

age = int(input(" Please Enter Your Age Here:  "))
if age < 18:
    print(" You are Minor ") 
    print(" You are not Eligible to Work ") 
else:
    if age >= 18 and age <= 60:
        print(" You are Eligible to Work ")
    else:
        print(" You are too old to work as per the Government rules")

OUTPUT:

Please Enter Your Age Here:  19
 You are Eligible to Work


Post a Comment

Previous Post Next Post