Gr10 AI ProgramSourceCode
Gr10 AI ProgramSourceCode
Python Programs
Note: Write the program and submit with printout of source code and
output in a A4 size sheet.
Program 1: Write a program to find the average height of the class.
height=[140,134,166,150,154,172,180,137,144,160]
Source Code:
height=[140,134,166,150,154,172,180,137,144,160]
sum=0
avg=0
for i in height:
sum=sum+i
avg=sum/10
print("The average height is :",avg)
Program 2: Write a program to take a number from the user and check ‘whether
the number is prime number or not’.
Source code:
num=int(input(“Enter a number”))
if num>1:
For x in range(2,num):
if num%2==0:
print(num,” is not a prime number”)
Break
else:
print(num, “is a prime number”)
else:
print(num,”is not a prime number”)
Program 3: Write a program which can take password/input from the user and
check the correct password, which is ‘SECRET’. The user can enter the password
only three times and the system should print ‘You cannot enter the house after
that’.
Source code:
flag=0
for i in range(0,3):
pwd=input(“Enter the password”)
if pwd==’SECRET’:
print(“Welcome”)
flag=1
else:
print(“Wong password”)
if flag==0:
print(“You cannot enter the house”)
Program 5: Write a program to print area of a house. Area is given in the list
‘Area’.
area=[“hall”, 660, “bedroom”, 444.25, “kitchen”, 220.55, “dining”, 215.80,
“bathroom”, 110.33]
Source code:
area=['hall', 660, 'bedroom', 444.25, 'kitchen', 220.55, 'dining', 215.80,
'bathroom', 110.33]
print(area)
ar=input("Enter the portion for which you want to see area ")
if ar=="Hall":
print(area[1])
elif ar=="Bed":
print(area[3])
elif ar=="Kit":
print(area[5])
elif ar=="Liv":
print(area[7])
elif ar=="Bath":
print (area[9])
else:
print ("Wrong input")
Program 6: Write a program to create a bar chart. Import the required libraries
Maruti_cars=[‘Ertiga’,’Ignis’,’Dzire’,’Brezza’,’Baleno’]
Sales=[8897,6754,5655,4000,7500]
Source code:
Sales=[8897,6754,5655,4000,7500]
plt.bar (Maruti_cars,Sales)
plt.xlabel(“Maruti_cars”)
plt.ylabel(“Sales”)
plt.title(“Maruti_cars and sales”)
#Rotate the x-axis labels for better readability
plt.xticks(rotation=45)
plt.show()
Program 7: Write a program to visualize a Line graph. Import the required
libraries
years_of_experience = [2,3,4,5,6]
salaries =[40000, 50000, 85000, 100000, 115000]
Source code:
import matplotlib.pyplot as plt
years_of_experience = [2,3,4,5,6]
salaries =[40000, 50000, 85000, 100000, 115000]
plt.plot (height, weight, marker='*')
plt.xlabel('years_of_experience')
plt.ylabel('salaries')
plt.title('Height and Weight')
plt.show()
Program 10: Write a program to do the following: Import the required libraries
a) Save the “healthcare_dataset.csv” file into a variable s.
Source code:
import pandas as pd
s=pd. read_csv("Z:\Grade 10\Grade 10 Lab Activities
\healthcare_dataset.csv")
print(s)
import pandas as pd
s=pd.read_csv(r"C:\Users\Admin\Desktop\healthcare_dataset.csv")
sl=s.sort_values(by='Age',ascending=False)
print(sl)
Program 11: Write a program to do the following : Import the required libraries
a) Save the “JaipurFinalCleanData.csv” file into a variable s.
Source code:
import pandas as pd
s=pd. read_csv("Z:\Grade 10\Grade 10 Lab Activities
\healthcare_dataset.csv")
print(s)
Program 12: Write a program to upload an image of your favorite city in the
world on the screen and give a proper title to it.
Source code:
import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\London.jpg’)
plt.imshow(img)
plt.title(‘My Favorite City’)
plt.axes(‘off’)
plt.show()
Program 13: Write a program to upload an image of your favorite food and
display the picture in RGB color mode.
Source code:
import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread(‘D:\Pasta.jpg’)
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title(‘My Favorite Food’)
plt.axes(‘off’)
plt.show()
Program 14: Write a program to upload an image of your favorite pet and display
the picture in grayscale mode.
Source code:
import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\Dog.jpg’,0)
plt.imshow (img, cmap=’gray’)
plt.title(‘My Pet’)
plt.axes(‘off’)
plt.show()
Program 15: Write a program to upload an image of your favorite pet and crop
the image.
Source code:
import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\Dog.jpg’,0)
roi=img[20:230,120:372]
plt.imshow(cv2.cvtColor(roi,cv2.COLOR_BGR2RGB)
plt.title(‘My Pet’)
plt.axes(‘off’)
plt.show()
______________________________________________________________________