ALPINE PUBLIC SCHOOL
(Junction Road, Khurja)
PRACTICAL FILE
AI (417)
CLASS-X
Session: 2024-25
SUBMITTED BY:
Name: ………………… …………………….
Roll No. …… ……
Class &Section: X ……
1|Page
CERTIFICATE
To: whom so ever it may concern.
This is to certify that (Name) ………………….. …
of Class X of ALPINE PUBLIC SCHOOL, KHURJA,
Roll Number ……… has carried out this practical work
in Subject-ARTIFICIAL INTELIGENCE (Code-417)
during the academic year 2024-25.
Date: _ _ / 01 / 2025
Sig. Sig.
Internal Examiner: PRINCIPAL
…………………… …………………
INDEX
SR. PRACTICAL
NO.
1. Program to swap two numbers.
2. Program to input a number and display whether it is a prime or not.
3. Program to enter the length of three sides of a triangle and check
whether a triangle can be formed with the inputs or not. If a triangle
can be formed then display whether the triangle will be scalene,
isosceles or equilateral.
4. Program to input a number and check if it is a palindrome.
5. Program to input string and display it in reverse order.
6. Program to input a number and display its factorial.
7. Program to input two numbers and display the LCM of two numbers.
8. Program to calculate mean, median and mode using NumPy .
9. Program to plot a Pie Chart using Matplotlib.
Data=[45,23,41,78,65]
10. Program to plot Line Chart using Matplotlib and given data.
x_axis=[3,4,6,2,8]
y_axis=[ 9, 10, 8, 7, 6]
11. Program to create an array of 5 marks and display the average of
marks using NumPy package.
12. Program to read and display data from a CSV file.
13. Program to upload an image and display it in RGB color mode using
cv2 library.
14. Program to display stemming of words.
“words:","eating","eats","playing","crying"
15. Program to display Lemmatization of words.
"Words: eating ate eats reading better playing studies "
Practical-1.
# Program-1: Swap two numbers
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
temp = a
a = b
b = temp
print("After swapping:")
print("First number:", a)
print("Second number:", b)
OUTUT:
Enter the first number: 5
Enter the second number: 10
After swapping:
First number: 10
Second number: 5
Practical-2
# Program to input a number and display whether it is a prime or not.
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
print(f"{num} is not a prime number.")
break
else:
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
OUTPUT:
Enter a number: 11
11 is a prime number.
Practical-3
# Program to enter the length of three sides of a triangle and check whether a
triangle can be formed with the inputs or not. If a triangle can be formed then
display whether the triangle will be scalene, isosceles or equilateral.
a = int(input("Enter the length of the first side: "))
b = int(input("Enter the length of the second side: "))
c = int(input("Enter the length of the third side: "))
if a + b > c and a + c > b and b + c > a:
if a == b == c:
print("The triangle is an Equilateral
triangle.")
elif a == b or b == c or a == c:
print("The triangle is an Isosceles triangle.")
else:
print("The triangle is a Scalene triangle.")
else:
print("A triangle cannot be formed with the given
sides.")
OUTPUT:
Enter the length of the first side: 5
Enter the length of the second side: 5
Enter the length of the third side: 5
The triangle is an Equilateral triangle.
Practical-4
# Program to check if a number is a palindrome
num = input("Enter a number: ")
if num == num[::-1]:
print(f"{num} is a palindrome.")
else:
print(f"{num} is not a palindrome.")
OUTPUT:
Enter a number: 121
121 is a palindrome.
Practical-5.
# Program to input string and display it in reverse order.
input_string = input("Enter a string: ")
reversed_string = ""
for char in input_string:
reversed_string = char + reversed_string
print("Reversed string:", reversed_string)
OUTPUT:
Enter a string: hello
Reversed string: olleh
Practical-6.
# Program to input a number and display its factorial.
num = int(input("Enter a number: "))
# Calculate the factorial using a loop
factorial = 1
for i in range(1, num + 1):
factorial *= i
# Display the factorial
print("Factorial of", num, "is:", factorial)
OUTPUT:
Enter a number: 5
Factorial of 5 is: 120
Practical-7.
Program to input two numbers and display the LCM of two numbers.
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
greater = max(num1, num2)
while True:
if greater % num1 == 0 and greater % num2 == 0:
lcm = greater
break
greater += 1
print("LCM of", num1, "and", num2, "is:", lcm)
OUTPUT:
Enter the first number: 4
Enter the second number: 5
LCM of 4 and 5 is: 20
Practical-8.
Program to calculate mean, median and mode using NumPy.
import statistics
d=[95, 90, 49, 71, 90, 100, 55]
m1=statistics.mean(d)
m2=statistics.median(d)
m3=statistics.mode(d)
print(“ The mean is:”, m1)
print(“ The median is:”, m2)
print(“ The mode is:”, m3)
OUTPUT:
The mean is : 78.57142857142857
The median is: 90
The mode is: 90
Practical-9.
# Program to plot a Pie Chart using Matplotlib.
import matplotlib.pyplot as plt
# Data for the pie chart
data = [45, 23, 41, 78, 65]
labels = ['A', 'B', 'C', 'D', 'E']
plt.pie(data, labels=labels, autopct='%1.1f%%',
startangle=90)
plt.axis('equal')
plt.title("Pie Chart of Data")
plt.show()
OUTPUT:
Pie Chart of data
A B C D E
Practical-10.
# Program to plot Line Chart using Matplotlib and given
data.
x_axis=[3,4,6,2,8]
y_axis=[ 9, 10, 8, 7, 6]
import matplotlib.pyplot as plt
x_axis = [3, 4, 6, 2, 8]
y_axis = [9, 10, 8, 7, 6]
plt.plot(x_axis, y_axis, marker='o', linestyle='-',
color='b', label="Line Chart")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
plt.title("Line Chart Example")
plt.grid(True)
plt.legend()
plt.show()
OUTPUT:
y
12
10
0
0 1 2 3 4 5 6 7 8 9
Practical-11.
# Program to create an array of 5 marks and display the average of marks using
NumPy package.
import numpy as np
marks = np.array([85, 90, 78, 92, 88])
average = np.mean(marks)
print(f"The average of the marks is: {average:.2f}")
OUTPUT:
The average of the marks is: 86.60
Practical-12.
Program to read and display data from a CSV file.
import pandas as pd
s=pd.read_csv("C:/Users/welcome/Desktop/student.csv ")
print(s.head())
print(s.tail(3))
OUTPUT:
SR NO. Name Class Section
7. Ravi X A
8. Naman X B
9. Raj X C
Practical-13.
Program to upload an image and display it in RGB color mode using cv2 library.
import cv2
from matplotlib import pyplot as plt
import numpy as np
img =
cv2.imread('C:/Users/welcome/Desktop/school.jpg',1)
print(img.min())
print(img.max())
plt.imshow(img)
plt.title('My School')
plt.axis('off')
plt.show()
OUTPUT:
Practical-14.
#Program to display stemming of words.
“words:","eating","eats","playing","crying"
import spacy
from nltk.stem import PorterStemmer
#stemming
print("Stemming")
print("words:","eating","eats","playing","crying")
stemmer=PorterStemmer()
words=["eating","eats","playing","crying"]
for word in words:
print(word, ":", stemmer.stem(word))
OUTPUT:
Stemming
words: eating eats playing crying
eating : eat
eats : eat
playing : play
crying : cri
Practical-15.
#Program to display Lemmatization of words.
"Words: eating ate eats reading better playing studies "
#Lemmatization
import spacy
print("Lemmatization")
print("Words:eating ate eats reading better playing
studies ")
nlp=spacy.load("en_core_web_sm")
doc=nlp("eating ate eats reading better playing
studies")
for token in doc:
print(token, ":", token.lemma_)
OUTPUT:
Lemmatization
Words: eating ate eats reading better playing studies
eating : eat
ate : eat
eats : eat
reading : read
better : well
playing : play
studies : study