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 = [Link](speed)
mdn = [Link](speed)
md = [Link](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 [Link] as plt
import numpy as np
x = [Link]([2,9])
y = [Link]([5,10])
[Link](x, y)
[Link]()
4. Write a program to display a scatter chart for the following points (2,5),
(9,10),(8,3),(5,7),(6,18).
import [Link] as plt
x =[2,9,8,5,6]
y =[5,10,3,7,18]
[Link](x, y, c ="blue")
[Link]()
5. Read csv file saved in your system and display 10 rows.
import pandas as pd
df=pd.read_csv(‘C:\[Link]’)
print([Link](10))
Output
6. Read csv file saved in your system and display its information
import pandas as pd
df=pd.read_csv(‘C:\[Link]’)
print([Link](10))
print([Link])
print([Link])
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"]
[Link](marks,labels=subjects, autopct='%1.2f%%')
[Link]()
Output::::
COMPUTER VISION
8. Write a program to read an image and display using Python
import cv2
from matplotlib import pyplot as plt
img = [Link]('c:\[Link]')
[Link](img)
[Link]('Man')
[Link]('off')
[Link]()
Output::::
9. Write a program to read an image and identify its shape using Python
import cv2
from matplotlib import pyplot as plt
img = [Link]('c:\[Link]')
[Link](img)
[Link]('Man')
[Link]('off')
[Link]()
print([Link])
Output:::
10. Write a program to convert the image to grayscale
import cv2
from matplotlib import pyplot as plt
img = [Link]('[Link]',0)
[Link](img, cmap = 'gray', interpolation = 'bicubic')
[Link]('Man')
[Link]('off')
[Link]()
Output::
11. Write a program to crop an image
import cv2
from matplotlib import pyplot as plt
import numpy as np
img = [Link]('[Link]')
roi = img[1500:2500,1000:2000]
[Link]([Link](roi, cv2.COLOR_BGR2RGB))
[Link]('man')
[Link]('off')
[Link]()
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 = [Link]()
str2 = [Link]()
# 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:::
****