Class X - Practicals of AI
Class X - Practicals of AI
1/X/Practical File
4. Write a program to calculate Area and Perimeter of a rectangle.
l=int(input('Enter the length in cm: '))
b=int(input('Enter the breadth in cm: '))
area=l*b
p=2*(l+b)
print('Area of the rectangle is',area,'sq. cm')
print('Perimeter of the rectangle is',p,'cm')
2/X/Practical File
8. Write a program to Access the items in the List.
fruits = [ ‘ Apple’ , ‘ Banana ’, ‘Cherry’ , ‘Orange’]
print (fruits [1]) print (fruits [3])
13. Write a program to Print Dictionary object with its keys and values.
fruits = {‘apple’ : ‘An Apple a day keeps the doctor away’ , ‘banana’ : ‘It is good for
digestion’, ‘Cherry’ : ‘Cherry is a good source for fibre and vitamins’}
print(fruits)
print(fruits [‘apple]’)
print(fruits [‘banana]’)
print(fruits [‘cherry]’)
3/X/Practical File
14. Create a list in Python of children selected for science quiz with following names-
Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik Perform the following tasks
on the list in sequence.
list=['Arjun','Sonakshi','Vikram','Sandhya','Sonal','Isha','Kartik'] print('Initial List:',list)
list.remove('Vikram')
print('List after removing Vikram:',list)
list.append('Jay')
print('List after adding Jay at the end:',list)
del list[2]
print('List after removing second item:',list)
15. Create a list List_1= [10,20,30,40]. Add the elements [14,15,12] using extend function.
Now sort the final list in ascending order and print it.
List_1=[10,20,30,40]
List_1.extend([14,15,12])
print("List after adding elements is",List_1)
List_1.sort()
print("Sorted list in ascending order is",List_1)
16. Write a program to add the elements of the two lists. list1=[52,93,156,643,6]
list2=[75,93,96,16,4,55,1546]
print('First list is:',list1)
print('Second list is:',list2)
list1.extend(list2)
print('Result after adding both the list is:',list1)
print('The sum of the list is:',sum(list1))
17. Write a program to find a person is eligible for casting vote or not.
Age = int (input ( “Enter the Age of the person = “) )
if Age > = 18 :
print (“ He is eligible to cast the vote.”)
else :
print (“ He is not eligible to cast the vote.”)
4/X/Practical File
18. Write a Python program that inputs a number and checks whether the given number
is odd or even.
num=int(input(“Enter a number=”))
if (num%2==0):
print(“This number is Even.”)
else:
print(“This number is Odd.”)
20. Write a program to find whether a number is a Positive Number, Negative Number
or Zero.
Num = int ( input (“ Enter a Number = “))
if Num>0 :
print ( “ This is a Positive Number.”)
elif Num = = 0 :
print ( “ This Number is Zero.”)
else :
print ( “ This is a Negative Number.”)
21. Write a program for a student reward if his marks are as follows:
22. Write a program to run through a list and print each element
fruits = [ “ Apple ”, “ Banana ”, “ Cherry ”]
for x in fruits :
print ( x )
print (“ Above is the List of Fruits.”)
23. Write a program to print the list of Numbers using For loop.
num = [ 0,2,5,9,12,16,19,21,23,22,25 ]
for elem in num :
print ( elem )
else:
print (“ No Item Left in the List.”)
24. Write a Python program to print table of a given number. n=int(input("Enter the
number to print the tables for:"))
for i in range(1,11):
print(n,"x",i,"=",n*i)
25. Write a Python Program to Print the numbers in reverse order using WHILE Loop.
a=10
while (a>0):
print(a)
a=a-1
print('end')
26. Write a Python Program to calculate and print the factorial of a number using WHILE
Loop.
sum=0
a=0
while(a<6):
sum=sum+a
a=a+1
print(“Factorial of number is=”,sum)
6/X/Practical File
27. To calculate the roots of Quadratic Equation by checking the value of discriminant.
n1 = 6789
rev = 0
while n1 > 0:
digit = n1 % 10
rev = rev * 10 + digit
n1 //= 10
print(6789)
print(rev)
31. Write a program to calculate mean, median and mode using Numpy.
import numpy
import statistics as stats
num_list = [79, 85, 80, 68, 98, 34, 90, 125, 63, 72, 82, 53, 91]
mean = numpy.mean(num_list)
median = numpy.median(num_list)
mode = stats.mode(num_list)
32. Write a program to display line chart from (2,5) to (9,10) using matplotlib library.
p1 = [2, 5]
p2 = [9, 10]
8/X/Practical File
x_axis = [p1[0], p2[0]]
y_axis = [p1[1], p2[1]]
plt.plot(x_axis, y_axis)
plt.show()
33. Write a program to read csv file saved in the system and display 10 rows.
import pandas as pd
dframe=pd.read_csv("C:/Users/Admin/Downloads/organizations-100.csv”, nrows=10)
print("First 10 rows: ", dframe.head(10))
34. Write a program to read csv file saved in the system and display its information.
import pandas as pd
file=pd.read_csv("C:/Users/Admin/Downloads/organizations-100.csv”)
print(file)
35.Write a program to read an image and identify its shape using Python.
import cv2
image = cv2.imread("C:/Users/Abc/downloads/tree.png")
print("Shape of the image: ", image.shape)
9/X/Practical File