Informatics Practices

Decision Making in Python | if, if-else, if-elif-else and Nested if | Complete Notes | CBSE Class 11 Informatics Practices (2026–27)

Class 11 · Informatics Practices

Decision Making in Python | if, if-else, if-elif-else and Nested if

In real life, we make decisions every day based on different situations. For example, if it is raining, we carry an umbrella. If we score more than 33 marks, we pass the examination; otherwise, we fail. Similarly, a computer program also needs to make decisions based on certain conditions. Python provides decision-making statements that allow a program to execute different blocks of code depending on whether a condition is True or False.


Learning Outcomes

After studying this chapter, you will be able to:

  • Understand the need for decision making in Python.
  • Explain the flow of control in a program.
  • Use the if statement.
  • Use the if-else statement.
  • Understand conditions using relational and logical operators.
  • Develop simple Python programs using decision-making statements.

What is Decision Making?

Definition

Decision making is the process of selecting one action from multiple alternatives based on the evaluation of a condition.

In Python, decision-making statements evaluate a condition. If the condition is True, one block of statements is executed. If it is False, another block (if available) is executed.


Why is Decision Making Important?

  • Helps programs take intelligent decisions.
  • Allows different actions for different situations.
  • Makes programs interactive.
  • Avoids unnecessary execution of statements.
  • Forms the basis of real-world applications such as login systems, ATM software, online shopping websites, and examination systems.

Real-Life Examples

Condition Decision
If it rains Carry an umbrella.
If marks are greater than or equal to 33 Student passes.
If age is 18 or above Eligible to vote.
If password is correct Allow login.
If account balance is sufficient Allow withdrawal.

Flow of Control

The order in which statements are executed in a program is called the flow of control.

Normally, Python executes statements one after another from top to bottom. Decision-making statements change this normal flow by executing code only when a specified condition is satisfied.


Conditions in Python

A condition is an expression that evaluates to either True or False.

Examples

10 > 5
25 == 20
15 != 8
100 >= 50
Condition Result
10 > 5 True
8 < 2 False
20 == 20 True
15 != 15 False

Relational Operators Used in Conditions

Operator Meaning Example
== Equal to a == b
!= Not equal to a != b
> Greater than a > b
< Less than a < b
>= Greater than or equal to a >= b
<= Less than or equal to a <= b

Logical Operators Used in Conditions

Operator Purpose
and Returns True if both conditions are True.
or Returns True if at least one condition is True.
not Reverses the result of a condition.

The if Statement

Definition

The if statement executes a block of code only when the specified condition is True.


Syntax of if Statement

if condition:
    statement(s)

Important: The block of statements must be properly indented.


Flowchart of if Statement


        Condition
            |
      +-----+------+
      |            |
    True        False
      |
 Execute Block
      |
    Next Statement

Example 1: Positive Number

num = int(input("Enter a number: "))

if num > 0:
    print("Positive Number")

Sample Output

Enter a number: 15
Positive Number

Example 2: Eligibility to Vote

age = int(input("Enter your age: "))

if age >= 18:
    print("Eligible to Vote")

Sample Output

Enter your age: 21
Eligible to Vote

Important Note

Remember

If the condition in an if statement is False, Python skips the block of statements and continues executing the next statement after the if block.


The if-else Statement

Definition

The if-else statement provides two alternative blocks of code. One block executes if the condition is True, and the other executes if the condition is False.


Syntax of if-else Statement

if condition:
    statement(s)
else:
    statement(s)

Flowchart of if-else Statement


         Condition
             |
      +------+------+
      |             |
    True         False
      |             |
 Execute IF    Execute ELSE
      |             |
      +------+------+
             |
      Next Statement

Example 3: Pass or Fail

marks = int(input("Enter marks: "))

if marks >= 33:
    print("Pass")
else:
    print("Fail")

Sample Output

Enter marks: 58
Pass

Example 4: Even or Odd Number

num = int(input("Enter a number: "))

if num % 2 == 0:
    print("Even Number")
else:
    print("Odd Number")

Sample Output

Enter a number: 17
Odd Number

Real-Life Application

An ATM machine checks whether the account balance is sufficient before allowing a cash withdrawal. If the balance is available, the transaction is processed; otherwise, an "Insufficient Balance" message is displayed. This is a practical example of the if-else statement.


Common Mistakes

Mistake Correct Practice
Forgetting the colon (:) after if or else. Always end the condition with a colon.
Incorrect indentation. Indent all statements inside the block consistently.
Using = instead of ==. Use == for comparison.
Writing Else instead of else. Python keywords are case-sensitive.

Continue with Part 2 → if-elif-else, Nested if, comparison table, solved programs, interview questions, quick revision, CBSE exam tips, and summary.