FREE E LEARNING PLATFORM
☰ HOMEEXCEPTIONSOOPSJVMINTRO
×

Python Syllabus

AKTU Python Syllabus AKTU Python Freshers AKTU Python Advanced AKTU Pyton PYQ AKTU Pyton PYQS 2026 AKTU Pyton PYQS 2025 AKTU Pyton PYQS 2024

Unit I Introduction

Introduction to Python History of Python Features of Python Applications of Python Python Installation Python IDE Python Program Life Cycle First Python Program Blocks & Indentation Comments Keywords Identifiers Variables Input & Output Data Types Numeric Data Types Type Conversion Python Operators

Unit II Control Statements

if Statement if...else Statement Nested if elif Statement for Loop range() Function while Loop Nested Loops break Statement continue Statement pass Statement else with Loop

Unit III Complex Data Types

Strings String Operations String Methods String Built-in Functions Lists List Slicing List Methods List Built-in Functions Tuples Tuple Methods Dictionaries Dictionary Methods Dictionary Built-in Functions Python Built-in Functions Python Functions User Defined Functions Lambda Functions Recursive Functions

Unit IV File Handling

Introduction to File Handling open() read() readline() readlines() write() writelines() File Pointer seek() tell() File Modes

Unit V Packages & GUI

Modules Packages NumPy Pandas Matplotlib Tkinter Introduction Tkinter Widgets Button Widget Label Widget Entry Widget Frame Widget Menu Widget Event Handling Programming with IDE Tkinter Mini Project

Python Programs

100+ Solved Programs Pattern Programs File Programs Tkinter Programs

AKTU Questions

Unit I Questions Unit II Questions Unit III Questions Unit IV Questions Unit V Questions Viva Questions Python MCQs

Previous Papers

AKTU 2026 (Solved) AKTU 2025 (Solved) AKTU 2024 (Solved) AKTU 2023 (Solved) AKTU 2022 (Solved)
 


Python Nested if Statement

A nested if statement means an if statement placed inside another if statement. It is used when a second condition needs to be checked only after the first condition is true.

Nested if statements are useful when a program has multiple levels of decision making.

Syntax of Nested if Statement

if condition1:
    if condition2:
        statement

Here, the inner if statement is executed only when the outer if condition is True.


Simple Nested if Example

age = 25

if age >= 18:
    if age <= 60:
        print("Age is between 18 and 60")
Output:
Age is between 18 and 60

First, the outer condition age >= 18 is checked. If it is true, the inner condition age <= 60 is checked.


Nested if with User Input

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

if age >= 18:
    if age <= 60:
        print("You are an adult.")
Example:
Enter your age: 25
You are an adult.

The inner condition is checked only when the user enters an age of 18 or above.


Nested if with else

An else block can be used with the inner if statement.

age = 20

if age >= 18:
    if age >= 21:
        print("Eligible")
    else:
        print("Adult but below 21")
else:
    print("Below 18")
Output:
Adult but below 21

The outer condition checks whether the person is at least 18. The inner condition then checks whether the age is at least 21.


Nested if for Checking Number

number = 20

if number > 0:
    if number % 2 == 0:
        print("Positive even number")
Output:
Positive even number

The first condition checks whether the number is positive. If it is positive, the second condition checks whether it is even.


Nested if for Positive and Negative Numbers

number = -10

if number != 0:
    if number > 0:
        print("Positive number")
    else:
        print("Negative number")
else:
    print("Zero")
Output:
Negative number

The outer condition first checks whether the number is not zero. The inner condition then determines whether it is positive or negative.


Nested if for Student Result

marks = 75

if marks >= 40:
    if marks >= 75:
        print("Pass with distinction")
    else:
        print("Pass")
else:
    print("Fail")
Output:
Pass with distinction

The outer if checks whether the student has passed. If the student passes, the inner if checks for distinction.


Nested if with Multiple Conditions

age = 25
has_id = True

if age >= 18:
    if has_id:
        print("Entry allowed.")
    else:
        print("ID required.")
else:
    print("Age restriction applies.")
Output:
Entry allowed.

The second condition is checked only after the age condition is satisfied.


Nested if with String

username = "admin"
password = "python123"

if username == "admin":
    if password == "python123":
        print("Login successful")
    else:
        print("Incorrect password")
else:
    print("Invalid username")
Output:
Login successful

The password is checked only when the username is correct.


Nested if with Membership Operator

fruits = ["apple", "banana", "mango"]

if "mango" in fruits:
    if len(fruits) >= 3:
        print("Mango is available and the list has at least 3 fruits.")
Output:
Mango is available and the list has at least 3 fruits.

Nested if with Comparison Operators

a = 50
b = 30

if a > b:
    if a > 40:
        print("a is greater than b and 40")
Output:
a is greater than b and 40

Nested if with Logical Operators

Logical operators can also be used inside nested conditions.

age = 25
salary = 40000

if age >= 18:
    if salary >= 30000 and salary <= 100000:
        print("Eligible")
Output:
Eligible

Nested if with Three Levels

Python allows an if statement to be nested inside another nested if statement.

age = 25
has_id = True
has_ticket = True

if age >= 18:
    if has_id:
        if has_ticket:
            print("Entry allowed")
        else:
            print("Ticket required")
    else:
        print("ID required")
else:
    print("Not eligible")
Output:
Entry allowed

Here, three conditions are checked one after another. Each inner condition is checked only when the previous condition is true.


Nested if with Multiple Statements

marks = 85

if marks >= 40:
    print("Student has passed.")

    if marks >= 75:
        print("Student has scored distinction.")
        print("Excellent performance.")
Output:
Student has passed.
Student has scored distinction.
Excellent performance.

Importance of Indentation in Nested if

Indentation is especially important in nested if statements because it determines which statements belong to the outer and inner blocks.

age = 25

if age >= 18:
    print("Adult")

    if age >= 21:
        print("Age is 21 or above")
Output:
Adult
Age is 21 or above
Warning: Incorrect indentation can cause an IndentationError or change the logical structure of the program.

Nested if vs if-else

Nested if if-else
Contains an if statement inside another if statement. Contains an if block and an alternative else block.
Used for multiple levels of decision making. Used when two alternative paths are required.
The inner condition depends on the outer condition. The else block executes when the if condition is false.

Practical Example: ATM Access

card_inserted = True
pin_correct = True

if card_inserted:
    if pin_correct:
        print("Access granted")
    else:
        print("Incorrect PIN")
else:
    print("Please insert your card")
Output:
Access granted

Practical Example: Admission Eligibility

marks = 75
age = 19

if marks >= 60:
    if age >= 18:
        print("Eligible for admission")
    else:
        print("Age requirement not satisfied")
else:
    print("Marks requirement not satisfied")
Output:
Eligible for admission

Important Points

  • A nested if is an if statement inside another if statement.
  • The inner condition is checked only when the outer condition is true.
  • Nested if statements are useful for multiple levels of decision making.
  • Proper indentation is required for nested blocks.
  • An else can be associated with the inner or outer if.
  • Comparison and logical operators can be used in nested conditions.
  • Too many levels of nesting can make a program difficult to read.
Key Point: A nested if statement allows Python to make a decision inside another decision. The inner condition is evaluated only when the outer condition is satisfied.