15 Python Programs for Class 9 AI Practical File (CBSE 2025-26)

Your Class 9 AI practical file needs Python programs — and this page has all of them, written exactly the way your teacher and examiner expect: clean code, a comment header, and the output shown below each program.

Every program here is from the CBSE AI Class 9 (Subject Code 417) 2025-26 syllabus, Unit 5: Introduction to Python. No libraries, no shortcuts — just clean, basic Python that runs on any computer or online compiler.

What You’ll Learn

  • All 15 programs from the CBSE Class 9 Python suggested list, ready to copy into your practical file
  • How each program works, line by line
  • The expected output for every program so you can verify your work
  • How to format programs correctly for your practical file

Before You Start — Practical File Formatting Rules

Your teacher will check your practical file for presentation, not just correctness. Follow these rules for every program:

  • Start every program with a comment header that states what the program does: # Program to calculate Simple Interest
  • Use meaningful variable names: principal instead of p, length instead of l
  • Always include a print() statement so output is visible
  • Write the expected output below each program (either as a comment or in the output section of your file)
  • Do not use libraries (NumPy, Pandas, etc.) — Class 9 uses basic Python only

Section 1 — PRINT Programs (Programs 1–7)

These programs use print() to display output directly. No user input required.


Program 1: Print Personal Information

python

# Program to print personal information

print("Name: Arjun Sharma")
print("Father's Name: Rajesh Sharma")
print("Class: IX - A")
print("School Name: Delhi Public School")

Expected Output:

Name: Arjun Sharma
Father's Name: Rajesh Sharma
Class: IX - A
School Name: Delhi Public School

Replace the values with your own name, father’s name, class, and school name before submitting.


Program 2: Print a Star Pattern (Left Triangle)

python

# Program to print a left triangle star pattern using multiple print commands

print("*")
print("* *")
print("* * *")
print("* * * *")
print("* * * * *")

Expected Output:

*
* *
* * *
* * * *
* * * * *

Program 3: Print a Star Pattern (Right Triangle — Inverted)

python

# Program to print an inverted right triangle star pattern

print("* * * * *")
print("* * * *")
print("* * *")
print("* *")
print("*")

Expected Output:

* * * * *
* * * *
* * *
* *
*

Program 4: Find the Square of Number 7

python

# Program to find square of number 7

number = 7
square = number ** 2
print("Square of", number, "is:", square)

Expected Output:

Square of 7 is: 49

How it works: The ** operator means “to the power of”. 7 ** 2 means 7 × 7 = 49.


Program 5: Find the Sum of Two Numbers

python

# Program to find the sum of two numbers 15 and 20

num1 = 15
num2 = 20
total = num1 + num2
print("Sum of", num1, "and", num2, "is:", total)

Expected Output:

Sum of 15 and 20 is: 35

Program 6: Convert Kilometres to Metres

python

# Program to convert length given in kilometres into metres

kilometres = 5.5
metres = kilometres * 1000
print(kilometres, "kilometres =", metres, "metres")

Expected Output:

5.5 kilometres = 5500.0 metres

Program 7: Print Table of 5 (Up to 5 Terms)

python

# Program to print the table of 5 up to five terms

print("5 x 1 =", 5 * 1)
print("5 x 2 =", 5 * 2)
print("5 x 3 =", 5 * 3)
print("5 x 4 =", 5 * 4)
print("5 x 5 =", 5 * 5)

Expected Output:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25

Program 8: Calculate Simple Interest (Fixed Values)

python

# Program to calculate Simple Interest
# Given: principal_amount = 2000, rate_of_interest = 4.5, time = 10

principal_amount = 2000
rate_of_interest = 4.5
time = 10

simple_interest = (principal_amount * rate_of_interest * time) / 100

print("Principal Amount:", principal_amount)
print("Rate of Interest:", rate_of_interest, "%")
print("Time:", time, "years")
print("Simple Interest:", simple_interest)

Expected Output:

Principal Amount: 2000
Rate of Interest: 4.5 %
Time: 10 years
Simple Interest: 900.0

Formula: SI = (P × R × T) / 100


Section 2 — INPUT Programs (Programs 9–11)

These programs take values from the user using input(). Remember: input() always returns a string, so always convert it using int() or float() before doing calculations.


Program 9: Calculate Area and Perimeter of a Rectangle

python

# Program to calculate Area and Perimeter of a rectangle

length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))

area = length * breadth
perimeter = 2 * (length + breadth)

print("Area of Rectangle:", area)
print("Perimeter of Rectangle:", perimeter)

Expected Output (if user enters 10 and 5):

Enter the length of the rectangle: 10
Enter the breadth of the rectangle: 5
Area of Rectangle: 50.0
Perimeter of Rectangle: 30.0

Program 10: Calculate Area of a Triangle

python

# Program to calculate Area of a triangle with Base and Height

base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))

area = 0.5 * base * height

print("Area of Triangle:", area)

Expected Output (if user enters 8 and 6):

Enter the base of the triangle: 8
Enter the height of the triangle: 6
Area of Triangle: 24.0

Formula: Area = ½ × base × height


Program 11: Calculate Average Marks of 3 Subjects

python

# Program to calculate average marks of 3 subjects

marks1 = float(input("Enter marks in Subject 1: "))
marks2 = float(input("Enter marks in Subject 2: "))
marks3 = float(input("Enter marks in Subject 3: "))

average = (marks1 + marks2 + marks3) / 3

print("Average Marks:", average)

Expected Output (if user enters 85, 90, 78):

Enter marks in Subject 1: 85
Enter marks in Subject 2: 90
Enter marks in Subject 3: 78
Average Marks: 84.33333333333333

Tip for practical file: If your teacher wants the average rounded to 2 decimal places, use: print("Average Marks:", round(average, 2))


Section 3 — LIST Programs (Programs 12–13)

Lists store multiple values in one variable. These two programs cover all the list operations CBSE expects at Class 9 level.


Program 12: Science Quiz List — Multiple Operations

python

# Program to create and perform operations on a list of student names

# Create the list
students = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]

# Step 1: Print the whole list
print("Original list:", students)

# Step 2: Delete "Vikram" from the list
students.remove("Vikram")
print("After removing Vikram:", students)

# Step 3: Add "Jay" at the end
students.append("Jay")
print("After adding Jay:", students)

# Step 4: Remove the item at the second position (index 1)
students.pop(1)
print("After removing item at position 2:", students)

Expected Output:

Original list: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
After removing Vikram: ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
After adding Jay: ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
After removing item at position 2: ['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']

Important: Python lists use zero-based indexing. “Second position” means index 1 (counting from 0). So pop(1) removes the second item.


Program 13: Number List — Length, Slicing, and Negative Indexing

python

# Program to perform operations on a number list using indexing

num = [23, 12, 5, 9, 65, 44]

# Part a: Print the length of the list
print("Length of list:", len(num))

# Part b: Print elements from second to fourth position (positive indexing)
# Positions 2, 3, 4 = index 1, 2, 3 → use slice [1:4]
print("Elements from 2nd to 4th position:", num[1:4])

# Part c: Print elements from position third to fifth (negative indexing)
# 3rd from end = -4, 2nd from end = -3, 1st from end = -2 → slice [-4:-1]
print("Elements from 3rd to 5th position (negative indexing):", num[-4:-1])

Expected Output:

Length of list: 6
Elements from 2nd to 4th position: [12, 5, 9]
Elements from 3rd to 5th position (negative indexing): [5, 9, 65]

Slicing logic:

  • num[1:4] → starts at index 1, stops before index 4 → gives index 1, 2, 3
  • num[-4:-1] → -4 is the 4th from the end (value 5), stops before -1 → gives the 4th, 3rd, 2nd from the end

Section 4 — IF / FOR / WHILE Programs (Programs 14–15)


Program 14: Check if a Number is Positive, Negative, or Zero

python

# Program to input a number and check if it is positive, negative or zero

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

if number > 0:
    print(number, "is a Positive number.")
elif number < 0:
    print(number, "is a Negative number.")
else:
    print("The number is Zero.")

Expected Output (if user enters -7):

Enter a number: -7
-7 is a Negative number.

How elif works: elif means “else if” — it checks a second condition only when the first if condition is False. You can chain as many elif blocks as needed.


Program 15: Print Sum of First 10 Natural Numbers

python

# Program to print the sum of first 10 natural numbers using a for loop

total = 0

for i in range(1, 11):
    total = total + i

print("Sum of first 10 natural numbers:", total)

Expected Output:

Sum of first 10 natural numbers: 55

How it works:

  • range(1, 11) generates numbers 1 through 10 (stops before 11)
  • Each number i is added to total one by one
  • After the loop ends, total holds the final sum: 1+2+3+4+5+6+7+8+9+10 = 55

Quick Revision Box

ConceptWhat It DoesExample
print()Displays output on screenprint("Hello")
input()Takes user input (always returns string)x = input("Enter: ")
int() / float()Converts string to numberint("15") → 15
**Exponent (power)7 ** 2 → 49
append()Adds item to end of listlist.append("Jay")
remove()Removes item by valuelist.remove("Vikram")
pop(i)Removes item at index ilist.pop(1)
len()Returns number of items in listlen([1,2,3]) → 3
range(a, b)Generates numbers from a to b-1range(1, 6) → 1,2,3,4,5

Practice Questions

Q1 (2 marks): Write a Python program to calculate the Simple Interest when principal = 5000, rate = 6, and time = 3 years.

Model Answer:

python

# Program to calculate Simple Interest
principal = 5000
rate = 6
time = 3
simple_interest = (principal * rate * time) / 100
print("Simple Interest:", simple_interest)

Output: Simple Interest: 900.0


Q2 (MCQ): What will be the output of the following code?

python

num = [10, 20, 30, 40, 50]
print(num[2])

a) 10   b) 20   c) 30   d) 40

Answer: c) 30 — List indexing starts at 0, so index 2 is the third element.


Frequently Asked Questions

Q1: Do I need to submit all 15 programs or can I choose a few? The CBSE 2025-26 syllabus (Subject Code 417) lists these as the suggested program list for Unit 5. Your school may ask for a selection or all of them — check with your teacher for the exact count required in your practical file. Having all 15 ready means you are fully prepared regardless of what is asked.

Q2: My program runs correctly on the online compiler but fails at school. Why? School computers often run older versions of Python or have different settings. The most common fix: make sure you are using print() with parentheses — print "Hello" (without parentheses) only works in Python 2, not Python 3. All programs above are Python 3.

Q3: Can I use a loop for the star pattern programs instead of multiple print statements? Yes — and it would be shorter code. However, CBSE specifically says “using multiple print commands” for the pattern programs. Use the print() version in your practical file to match the syllabus wording exactly.