ARMY PUBLIC SCHOOL, RK PURAM, SECUNDERBAD
ARTIFICIAL INTELLIGENCE (SUBJECT CODE -417)
LIST OF PROGRAMS
Important Programs for Practical
CLASS X 2023-24
(CBSE Boards 2024)
DATA SCIENCE
1. Write a program to add the elements of the two lists.
list1 = [1, 'a']
list2 = [3, 4, 5]
list3 = list1 + list2
print(list3)
Output:
[1, 'a', 3, 4, 5]
2. Write a program to calculate mean, median and mode using Numpy
import numpy as np
import statistics as stat
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
mn = np.mean(speed)
mdn = np.median(speed)
md = stat.mode(speed)
print(mn)
print(mdn)
print(md)
Output:
89.76923076923077
87.0
86
3. Write a program to display line chart from (2,5) to (9,10).
import matplotlib.pyplot as plt
import numpy as np
x = np.array([2,9])
y = np.array([5,10])
plt.plot(x, y)
plt.show()
4. Write a program to display a scatter chart for the following points (2,5),
(9,10),(8,3),(5,7),(6,18).
import matplotlib.pyplot as plt
x =[2,9,8,5,6]
y =[5,10,3,7,18]
plt.scatter(x, y, c ="blue")
plt.show()
5. Read csv file saved in your system and display 10 rows.
import pandas as pd
df=pd.read_csv(‘C:\JaipurFinalCleanData.csv’)
print(df.head(10))
Output
6. Read csv file saved in your system and display its information
import pandas as pd
df=pd.read_csv(‘C:\JaipurFinalCleanData.csv’)
print(df.head(10))
print(df.shape)
print(df.dtypes)
Output:::
7. Program to Plot a pie chart for marks scored in various subjects
from matplotlib import pyplot as pltimport
numpy as np marks=[23,45,34,41,13,49,78]
subjects=["Eng","Hindi","Sanskrit","Maths", "Science","Social","AI"]
plt.pie(marks,labels=subjects, autopct='%1.2f%%')
plt.show()
Output::::
COMPUTER VISION
8. Write a program to read an image and display using Python
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('c:\man.jpg')
plt.imshow(img)
plt.title('Man')
plt.axis('off')
plt.show()
Output::::
9. Write a program to read an image and identify its shape using Python
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('c:\man.jpg')
plt.imshow(img)
plt.title('Man')
plt.axis('off')
plt.show()
print(img.shape)
Output:::
10. Write a program to convert the image to grayscale
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('man.jpg',0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.title('Man')
plt.axis('off')
plt.show()
Output::
11. Write a program to crop an image
import cv2
from matplotlib import pyplot as plt
import numpy as np
img = cv2.imread('man.jpg')
roi = img[1500:2500,1000:2000]
plt.imshow(cv2.cvtColor(roi, cv2.COLOR_BGR2RGB))
plt.title('man')
plt.axis('off')
plt.show()
Output:::
ADVANCE PYTHON
12. Python program to find the factorial of a number provided by the user.
# To take input from the user
num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num+1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:::
13. Python program to check if the number is an Armstrong number or not
#Armstrong Number is the sum of cubes of each digit is equal to the number itself.
#(Ex.153=1x1x1+5x5x5+3x3x3)
# take input from the user
num = int(input("Enter a number: "))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output:::
14. Python program to check if two strings are anagrams using sorted()
str1 = "Race"
str2 = "Care"
# convert both the strings into
lowercasestr1 = str1.lower()
str2 = str2.lower()
# check if length is same
if(len(str1) == len(str2)):
# sort the strings sorted_str1 = sorted(str1)sorted_str2 = sorted(str2)
# if sorted char arrays are same
if(sorted_str1 == sorted_str2):
print(str1 + " and " + str2 + " are anagram.")
else:
print(str1 + " and " + str2 + " are not anagram.")
else:
print(str1 + " and " + str2 + " are not anagram.")
Output:::
15. Palindrome program in python language
"""A palindrome is a number or letter that remains the same even if the number and
letters are inverted. 121, 11, 414, 1221, 74747 are the palindrome numbers."""
num = int(input("Enter a value:"))
temp = num
rev = 0
while(num > 0):
dig = num % 10
rev = rev * 10 + dig
num = num // 10
if(temp == rev):
print("This value is a palindrome number!")
else:
print("This value is not a palindrome number!")
Output:::
****