Posted on

## Python Decision Making

In decision making statement the control will flow only in one direction. Based upon the condition it will execute either True block or False block, here condition means relation between two operators. Decision statement “control” the flow of execution, they are also known as control statement.

There are two block’s if block and else block, if part is a true block and else part is a false block. The condition and expression will be written in if block.

Some logical conditions which are commonly used in Decision making statements are,

Python provides following decision making statements.

## if statements

If is an conditional statement, if the condition becomes true then the block of code will be executed. In if statement we use if as keyword.

Syntax

``````if expression:
statement  ``````

Example:

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

Output:

``A is greater than B``

## if-else statement

If the condition becomes true the true block will execute, if the condition becomes false the else block will execute.

Syntax:

``````if condition:
True block statements
else:
False block statements ``````

Example:

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

Output:

``B is greater than A``

## nested if statements

When an if statement contains another if statement then it is a nested if statement. The nested if statement allows us to check multiple conditions and will execute based upon the condition.

Syntax:

``````if expression_1:
statement
if expression_2:
statement
elif expression_3:
statement
else:
statement``````

Example:

``````age = 21
if age < 18:
print(" You are Minor and 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:

``You are Eligible to Work``

### 2 comment on “Python Decision Making”

• • 