CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
PART-C: PRACTICAL WORK
UNIT 5: INTRODUCTION TO PYTHON
Suggested Program List — Complete Solutions with Explanations
Subject Code: 417 — Artificial Intelligence
Class IX — Academic Year 2026-2027
Sri Aurobindo Mira Universal School, Keelamathur
How to use this document:
• Each question from the practical list is solved with a complete, ready-to-run Python program.
• Every program is followed by a sample output box and a step-by-step explanation in plain language.
• Programs are grouped by topic — PRINT, INPUT, LIST, and IF/FOR/WHILE — exactly as given in the
question paper.
• Type the programs yourself in the Python IDE or Jupyter Notebook to build muscle memory before
exams/practicals.
Page 1 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
PRINT Statement Programs
The print() function displays output on the screen. These programs build comfort with print(), string
formatting, basic arithmetic, and the use of multiple print statements together.
Q1. To print personal information like Name, Father's Name, Class, School Name.
print("Name :", "Aarav Kumar")
print("Father's Name :", "Suresh Kumar")
print("Class :", "IX - A")
print("School Name :", "Sri Aurobindo Mira Universal School")
Sample Output
Name : Aarav Kumar
Father's Name : Suresh Kumar
Class : IX - A
School Name : Sri Aurobindo Mira Universal School
Explanation: Four separate print() calls are used, each displaying one piece of personal information. Inside
print(), a label (like "Name :") is given first, followed by a comma and the actual value. The comma in
print() automatically adds a space between the two items, and aligning the colons with extra spaces makes
the output look neat, like a small bio-data card.
• print() can take multiple comma-separated values; Python prints them separated by a single space by
default.
• Hard-coded string values are used here — in real practicals you may replace them with your own
details.
Q2. To print the following patterns using multiple print commands.
# Pattern 1: A solid rectangle of stars
print("* * * * *")
print("* * * * *")
print("* * * * *")
print("* * * * *")
# Pattern 2: A right-angled triangle of stars
print("*")
print("* *")
print("* * *")
print("* * * *")
print("* * * * *")
Sample Output
* * * * *
* * * * *
* * * * *
* * * * *
*
* *
* * *
* * * *
* * * * *
Page 2 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
Explanation: Patterns are drawn purely using repeated print() statements — there is no loop here because
the task says "using multiple print commands." For Pattern 1, the same row of five stars is printed four times
to form a rectangle. For Pattern 2, each new print() statement adds one more star than the previous line,
which visually creates a triangle shape growing from one star at the top to five stars at the bottom.
• Each print() call automatically moves to a new line afterward, which is what stacks the rows on top of
each other.
• Once loops (for/while) are taught, the same patterns can be generated in 2-3 lines instead of
repeating print().
Q3. To find square of number 7.
number = 7
square = number ** 2
print("Square of", number, "is", square)
Sample Output
Square of 7 is 49
Explanation: The variable number stores the value 7. The exponent operator ** raises a number to a power,
so number ** 2 multiplies 7 by itself (7 × 7) to get the square. The result is stored in the variable square and
then displayed using print().
• ** is Python's power/exponent operator; number ** 2 is the same as number * number.
Q4. 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)
Sample Output
Sum of 15 and 20 is 35
Explanation: Two variables, num1 and num2, store the given numbers. The + operator adds them together
and the result is saved in total, which is then printed in a readable sentence.
Q5. To convert length given in kilometers into meters.
length_km = 5
length_m = length_km * 1000
print(length_km, "kilometers =", length_m, "meters")
Sample Output
5 kilometers = 5000 meters
Explanation: 1 kilometer equals 1000 meters, so the conversion is done by multiplying the length in
kilometers (length_km) by 1000. The result, length_m, gives the equivalent length in meters.
• Change the value of length_km to convert any other distance — the formula (km * 1000) stays the
same.
Q6. To print the table of 5 up to five terms.
number = 5
print(number, "x 1 =", number * 1)
print(number, "x 2 =", number * 2)
print(number, "x 3 =", number * 3)
Page 3 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
print(number, "x 4 =", number * 4)
print(number, "x 5 =", number * 5)
Sample Output
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
Explanation: The multiplication table of 5 is produced by multiplying 5 by 1, 2, 3, 4 and 5 in separate print()
statements — exactly five terms, as asked. Each line shows the multiplication expression along with its
result.
• This can later be rewritten compactly using a for loop with range(1, 6).
Q7. To calculate Simple Interest if principle_amount = 2000, rate_of_interest = 4.5, time = 10.
principle_amount = 2000
rate_of_interest = 4.5
time = 10
simple_interest = (principle_amount * rate_of_interest * time) / 100
print("Simple Interest =", simple_interest)
Sample Output
Simple Interest = 900.0
Explanation: Simple Interest is calculated with the standard formula SI = (P x R x T) / 100, where P is the
principal amount, R is the rate of interest, and T is the time in years. The three given values are stored in
variables exactly as named in the question, substituted into the formula, and the final interest is printed.
• The result is a float (900.0) because rate_of_interest is a decimal number (4.5), which makes the
whole expression a floating-point calculation.
Page 4 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
INPUT Statement Programs
The input() function lets the program take values from the user while it is running. Since input() always
returns text (a string), numeric values are converted using int() or float() before doing any calculation.
Q1. 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 the rectangle =", area)
print("Perimeter of the rectangle =", perimeter)
Sample Output
Enter the length of the rectangle: 12
Enter the breadth of the rectangle: 5
Area of the rectangle = 60.0
Perimeter of the rectangle = 34.0
Explanation: The user enters the length and breadth, which input() returns as text. Wrapping input() with
float() converts that text into a decimal number so arithmetic can be performed. Area is calculated as length
x breadth, and perimeter using the formula 2 x (length + breadth); both results are then displayed.
• float() is preferred over int() here because lengths can be decimal values like 4.5.
Q2. 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 the triangle =", area)
Sample Output
Enter the base of the triangle: 10
Enter the height of the triangle: 6
Area of the triangle = 30.0
Explanation: The area of a triangle is given by the formula (1/2) x base x height. After taking the base and
height from the user as decimal numbers, the program directly applies this formula and prints the area.
Q3. 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)
Sample Output
Enter marks in Subject 1: 85
Enter marks in Subject 2: 90
Enter marks in Subject 3: 78
Average marks = 84.33333333333333
Page 5 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
Explanation: The marks of three subjects are taken from the user one by one. They are added together and
the sum is divided by 3 (the number of subjects) to get the average, which is then displayed.
• The average can be rounded for a cleaner output using round(average, 2).
Q4. To calculate discounted amount with discount %.
price = float(input("Enter the original price: "))
discount_percent = float(input("Enter the discount percentage: "))
discount_amount = (price * discount_percent) / 100
final_price = price - discount_amount
print("Discount Amount =", discount_amount)
print("Price after Discount =", final_price)
Sample Output
Enter the original price: 1500
Enter the discount percentage: 20
Discount Amount = 300.0
Price after Discount = 1200.0
Explanation: The discount amount is found using the formula (price x discount%) / 100. This discount
amount is then subtracted from the original price to get the final price the customer actually pays. Both
values are displayed so the calculation is transparent.
Q5. To calculate Surface Area and Volume of a Cuboid.
length = float(input("Enter the length of the cuboid: "))
breadth = float(input("Enter the breadth of the cuboid: "))
height = float(input("Enter the height of the cuboid: "))
surface_area = 2 * (length * breadth + breadth * height + height * length)
volume = length * breadth * height
print("Surface Area of the cuboid =", surface_area)
print("Volume of the cuboid =", volume)
Sample Output
Enter the length of the cuboid: 4
Enter the breadth of the cuboid: 3
Enter the height of the cuboid: 2
Surface Area of the cuboid = 52.0
Volume of the cuboid = 24.0
Explanation: A cuboid's total surface area is given by 2 x (lb + bh + hl), covering all six rectangular faces,
while its volume is simply length x breadth x height. After taking the three dimensions as input, both
formulas are applied directly and the results are printed.
Page 6 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
LIST Programs
A list in Python is an ordered, changeable (mutable) collection of items written inside square brackets [].
These programs cover creating lists, indexing (positive and negative), and common list methods such as
insert(), remove(), append(), and extend().
Q1. Create a list of children selected for a science quiz with the names: Arjun, Sonakshi, Vikram,
Sandhya, Sonal, Isha, Kartik. Then: print the whole list, delete "Vikram", add "Jay" at the end,
and remove the item at the second position.
children = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
# 1. Print the whole list
print("Original list:", children)
# 2. Delete the name "Vikram" from the list
[Link]("Vikram")
print("After removing Vikram:", children)
# 3. Add the name "Jay" at the end
[Link]("Jay")
print("After adding Jay at the end:", children)
# 4. Remove the item which is at the second position (index 1)
[Link](1)
print("After removing item at 2nd position:", children)
Sample Output
Original list: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha',
'Kartik']
After removing Vikram: ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha',
'Kartik']
After adding Jay at the end: ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha',
'Kartik', 'Jay']
After removing item at 2nd position: ['Arjun', 'Sandhya', 'Sonal', 'Isha',
'Kartik', 'Jay']
Explanation: All seven names are first stored in a list called children. print(children) shows the entire list.
The remove() method searches the list for the value "Vikram" and deletes it by value (not by position).
append() adds "Jay" as a brand-new item at the very end of the list. Finally, since list positions start counting
from index 0, the "second position" is index 1, so pop(1) removes the item currently sitting at that index and
also shows what was removed.
• remove(value) deletes the first matching value; pop(index) deletes the item at a specific position and
returns it.
• Indexing in Python always starts at 0, so the 1st item is index 0 and the 2nd item is index 1.
Q2. Create a list num=[23,12,5,9,65,44]: print the length of the list, print the elements from
second to fourth position using positive indexing, and print the elements from third to fifth
position using negative indexing.
num = [23, 12, 5, 9, 65, 44]
# Length of the list
print("Length of the list:", len(num))
Page 7 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
# Elements from 2nd to 4th position using POSITIVE indexing
# 2nd position = index 1, 4th position = index 3 (slice end is exclusive, so use
4)
print("2nd to 4th element (positive index):", num[1:4])
# Elements from 3rd to 5th position using NEGATIVE indexing
# 3rd from end = index -3, 5th from end = index -5 (since slicing left-to-right,
write smaller index first)
print("3rd to 5th element from end (negative index):", num[-5:-2])
Sample Output
Length of the list: 6
2nd to 4th element (positive index): [12, 5, 9]
3rd to 5th element from end (negative index): [12, 5, 9]
Explanation: len(num) directly returns how many items the list holds. For the second task, since list
positions begin at index 0, the "2nd position" is index 1 and the "4th position" is index 3; the slice num[1:4]
picks indexes 1, 2 and 3 (the upper bound 4 is excluded). For the negative-indexing task, indexing from the
end starts at -1 for the last item, so the 3rd-from-last item is -3 and the 5th-from-last is -5; since a slice must
go from a smaller index to a larger one, the correct slice is num[-5:-2], which picks indexes -5, -4 and -3.
• Slicing syntax list[start:stop] always includes start but excludes stop.
• Negative indexes count backward from the end of the list: -1 is the last element, -2 the second-last,
and so on.
Q3. Create a list of first 10 even numbers, add 1 to each item in the list and print the final list.
even_numbers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
print("Original list of even numbers:", even_numbers)
# Add 1 to every item using list comprehension
final_list = [item + 1 for item in even_numbers]
print("Final list after adding 1 to each item:", final_list)
Sample Output
Original list of even numbers: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
Final list after adding 1 to each item: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
Explanation: The first ten even numbers (2 to 20) are stored directly in a list. A list comprehension [item + 1
for item in even_numbers] then goes through every item one at a time, adds 1 to it, and collects all the new
values into a brand-new list called final_list, which is printed at the end.
• A list comprehension is a short way of writing a for loop that builds a new list; it could equally be
written with a normal for loop and append().
Q4. Create a list List_1=[10,20,30,40]. Add the elements [14,15,12] using the extend function.
Sort the final list in ascending order and print it.
List_1 = [10, 20, 30, 40]
print("Original list:", List_1)
# Add elements [14, 15, 12] using extend()
List_1.extend([14, 15, 12])
print("After extend:", List_1)
# Sort the list in ascending order
Page 8 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
List_1.sort()
print("Final sorted list (ascending):", List_1)
Sample Output
Original list: [10, 20, 30, 40]
After extend: [10, 20, 30, 40, 14, 15, 12]
Final sorted list (ascending): [10, 12, 14, 15, 20, 30, 40]
Explanation: extend() takes another list, [14, 15, 12], and adds each of its elements individually onto the end
of List_1 (unlike append(), which would have added the whole [14, 15, 12] as one single nested item). After
extending, sort() rearranges all the elements of List_1 in increasing order, directly modifying the original list,
and the final result is printed.
• extend(other_list) merges another list's items in; append(other_list) would add it as one single nested
element instead.
• sort() sorts the list in place and returns None — there's no need (and no use) to write List_1 =
List_1.sort().
Page 9 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
IF, FOR, WHILE Programs
This section introduces decision-making (if/elif/else) and repetition (for and while loops) — the two building
blocks used in almost every real Python program.
Q1. Program to check if a person can vote.
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Sample Output
Enter your age: 20
You are eligible to vote.
Explanation: The user's age is taken as input and converted to an integer. The if condition checks whether
age is greater than or equal to 18, the minimum voting age in India. If the condition is True, the eligible
message is printed; otherwise the else block runs and prints the not-eligible message.
Q2. Program to check the grade of a student.
marks = float(input("Enter the marks obtained (out of 100): "))
if marks >= 90:
grade = "A"
elif marks >= 75:
grade = "B"
elif marks >= 60:
grade = "C"
elif marks >= 40:
grade = "D"
else:
grade = "Fail"
print("Grade:", grade)
Sample Output
Enter the marks obtained (out of 100): 82
Grade: B
Explanation: The marks are checked from the highest range downward using if/elif. Python tests each
condition in order and stops at the first one that is True, so a student scoring, say, 82 fails the first check (>=
90) but passes the second (>= 75) and is graded "B"; the remaining elif/else branches are then skipped
automatically.
• Only one branch of an if/elif/else chain ever runs — once a condition is True, the rest are skipped.
Q3. Input a number and check if the number is positive, negative or zero and display an
appropriate message.
number = float(input("Enter a number: "))
if number > 0:
print(number, "is a positive number.")
Page 10 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
elif number < 0:
print(number, "is a negative number.")
else:
print("The number is zero.")
Sample Output
Enter a number: -7
-7.0 is a negative number.
Explanation: There are exactly three possibilities for any number: greater than zero, less than zero, or equal
to zero. The if checks the positive case, the elif checks the negative case, and since neither could be true
only when the number is exactly 0, the final else safely catches that remaining case.
Q4. To print first 10 natural numbers.
for number in range(1, 11):
print(number)
Sample Output
1
2
3
4
5
6
7
8
9
10
Explanation: Natural numbers start from 1. range(1, 11) generates numbers from 1 up to (but not including)
11, giving exactly ten values: 1 through 10. The for loop visits each value in turn and prints it.
• range(start, stop) always stops one before the 'stop' value, which is why 11 is used to get up to 10.
Q5. To print first 10 even numbers.
count = 0
number = 2
while count < 10:
print(number)
number += 2
count += 1
Sample Output
2
4
6
8
10
12
14
16
18
20
Explanation: This program uses a while loop instead of for to show the same idea with manual counting.
number starts at 2 (the first even number) and count tracks how many numbers have been printed so far.
Page 11 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
Each pass through the loop prints the current number, then increases number by 2 to reach the next even
number, and increases count by 1. The loop keeps repeating only while count is less than 10, so it stops after
exactly ten even numbers have been printed.
• A while loop needs the programmer to update the counter (count += 1) manually, otherwise it will run
forever (an infinite loop).
Q6. To print odd numbers from 1 to n.
n = int(input("Enter the value of n: "))
for number in range(1, n + 1):
if number % 2 != 0:
print(number)
Sample Output
Enter the value of n: 12
1
3
5
7
9
11
Explanation: The user supplies the upper limit n. The for loop walks through every whole number from 1 to
n (n + 1 is used as the stop value so that n itself is included). Inside the loop, the if condition number % 2 != 0
uses the modulus operator % to find the remainder when number is divided by 2; if the remainder is not 0,
the number is odd, so it gets printed.
• The % (modulus) operator gives the remainder of a division and is the standard way to test odd/even
in Python: even numbers give remainder 0, odd numbers give remainder 1.
Q7. Program to find the sum of first 10 natural numbers.
total = 0
for number in range(1, 11):
total = total + number
print("Sum of first 10 natural numbers =", total)
Sample Output
Sum of first 10 natural numbers = 55
Explanation: A variable total is first set to 0 to act as a running sum (an accumulator). The for loop visits
each natural number from 1 to 10, and on every pass total = total + number adds the current number into
the running total. By the time the loop finishes, total holds the sum of all ten numbers, which is then
printed.
• This 'start at 0 and keep adding' pattern is called an accumulator pattern and is used very frequently in
loops.
Q8. Program to find the sum of all numbers stored in a list.
numbers = [12, 45, 7, 23, 56, 9]
total = 0
for value in numbers:
Page 12 of 13
CBSE AI (417) | Class IX | Unit 5 — Introduction to Python
total = total + value
print("List:", numbers)
print("Sum of all numbers in the list =", total)
Sample Output
List: [12, 45, 7, 23, 56, 9]
Sum of all numbers in the list = 152
Explanation: A sample list of numbers is created. As in the previous program, total starts at 0. The for loop
here goes directly over the list itself (for value in numbers), so on each pass value becomes one of the list's
items, which is added to total. After visiting every item, total contains the sum of the whole list.
• Python's built-in function sum(numbers) could replace the entire loop — sum(numbers) returns 152
directly — but writing the loop manually here shows how it works internally.
• for value in numbers loops directly over the items of a list, unlike for number in range(...), which loops
over a sequence of generated numbers.
Page 13 of 13