Class : X
Subject : Artificial Intelligence
Practical File
Chapter 9 : Introduction to Python Programs
1. Write a program to do basic arithmetic operations in Python.
a1 = int(input (“Enter 1st number=”))
a2 = int(input (“Enter 2nd number=”))
sum = a1 + a2
print (“ Sum of two Numbers = “, sum)
difference = a1 - a2
print (“ Difference of two Numbers = “, difference)
product= a1 * a2
print (“ Product of two Numbers = “, product)
quotient = a1 / a2
print (“ Quotient of two Numbers = “, quotient)
remainder = x % y
print (“ Remainder of two Numbers are = “, remainder)
exponentiation = x * * y
print (“ Power of two Numbers are = “, exponentiation)
integer_division= x / / y
print (“ Result of Integer Division of 2 Numbers are = “, integer_division)
2. Write a program to find maximum and minimum of 3 Integers
x =int( input (“Enter 1st number=”))
y = int( input (“Enter 2nd number=”))
z = int(input (“Enter 3rd number=”))
m = max ( x, y, z)
print (“Maximum number out of x, y and z is =” , m )
n = min ( x, y, z )
print ( “ Minimum number out of x, y and z is =” , n )
3. Write a program showcasing Relational and Logical Operators.
a=int(input("Enter the number a ="))
b=int(input(“Enter the number b ="))
c=((a<b) and (a==b))
print ("It will return = ", c)
d=((a<=b) or (a!=b))
print ("It will return = " , d)
e= not((a<b) and (a==b))
print("It will return=",e)
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')
5. Write a program to calculate average marks of 5 subjects.
Sci= float(input('Enter the marks in Science Subject: '))
Maths=float(input('Enter the marks in Maths Subject: '))
Hindi=float(input('Enter the marks in Hindi Subject: '))
Sst=float(input('Enter the marks in Sst Subject: '))
English=float(input('Enter the marks in English Subject: '))
avg=(Sci+Maths+Hindi+Sst+English)/5
print('Average marks in 5 subjects are ',avg)
6. Write a program to calculate Surface Area and Volume of a Cuboid.
l=int(input('Enter the length of the cuboid in cm: '))
b=int(input('Enter the breadth of the cuboid in cm: '))
h=int(input('Enter the height of the cuboid in cm: '))
SA=2*(l*b + b*h + h*l)
vol=l*b*h
print('The surface area of cuboid is', SA, 'cubic cm')
print('The volume of cuboid is',vol, 'cubic cm')
7. Write a program to swap two numbers.
x=5
y=10
temp=x
x=y
y=temp
print (‘The value of x and y before swapping is x=’,x, ‘and y=’,y)
print (‘The value of x and y after swapping is x=’,x, ‘and y=’,y)
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])
9. Write a program to Change the items in the List.
fruits = [ ‘ Apple’ , ‘ Banana ’, ‘Cherry’ , ‘Orange’]
print (fruits)
fruits [2] = ‘Grapes’
print (fruits)
10. Write a program to Access the items in the Tuples.
tup = (‘Physics’ , ‘Chemistry’, ‘Biology’, ‘Mathematics’)
print(tup)
11. Write a program to access a particular item in the Tuples.
animals = (‘tiger’ , ‘lion’ , ‘monkey’)
print (animals [1])
12. Write a program to Access the values in the Dictionary.
dict = {‘Name’ : ‘Zara’, ‘Age’ : 7, ‘Class’ : ‘First’)
print(dict [‘Name’])
print(dict [‘Age’])
print(dict [‘Class’])
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))
Chapter 10 : More about Python
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.”)
19. Write a program to find whether a Year is Leap Year or Not.
Year = int (input ( “Enter the Age of the person = “) )
if Year % 4 = = 0 :
print (“ This is a Leap Year.”)
else :
print (“ This is not a Leap Year ”)
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:
marks = float (input ( “Enter the Marks = “) )
if marks > 90 :
print (“ You get a Bicycle.”)
elif marks > 80 :
5/X/Practical File
print (“ You get a Calculator. ”)
elif marks > 70 :
print (“ You get A set of pens. ”)
else :
print (“ You get nothing. Try hard next time. ”)
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.
a=int(input('Enter the value of a: '))
b=int(input('Enter the value of b: '))
c=int(input('Enter the value of c: '))
d=b**2-4*a*c
if(d>0):
print('It has real and distinct roots')
alpha=(-b+d**2-0.5)/(2*a)
beta=(-b-d**2-0.5)/(2*a)
print('The roots are', alpha, 'and', beta)
elif(d==0):
print('It has real and same roots')
alpha=(-b-d**2-1/2)/2*a
print('The roots are', alpha, 'and', alpha)
else:
print('It has no real roots')
28. Write a program to reverse a number
n1 = 6789
rev = 0
while n1 > 0:
digit = n1 % 10
rev = rev * 10 + digit
n1 //= 10
print(6789)
print(rev)
29. Write a program to check whether a number is palindrome or not.
num=int(input('enter the number to be checked'))
rev = 0
temp=num
while temp > 0:
rem=temp % 10
rev = rem+(rev*10)
temp=int(temp/10)
if rev==num:
7/X/Practical File
print('It is a Pallindrome Number')
else:
print('It is not a Pallindrome Number')
30. Write a program to check whether a number is Armstrong or not.
num=int(input('enter the number to be checked'))
sum = 0
temp=num
while temp > 0:
rem=temp % 10
sum=sum+rem**3
temp=int(temp/10)
if sum==num:
print('It is a Armstrong Number')
else:
print('It is not a Armstrong Number')
Ch-11 Python Tools and Virtual Environment
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)
print("Mean: ", mean)
print("Median: ", median)
print("Mode: ", mode)
32. Write a program to display line chart from (2,5) to (9,10) using matplotlib library.
import matplotlib.pyplot as plt
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