0% found this document useful (0 votes)
901 views26 pages

Practical File Artificial Intelligence Class 10 For 2022-23 (Arnav Singh)

The document is a practical record file submitted for an Artificial Intelligence class. It includes an acknowledgement section thanking the teacher and school authorities. It also includes a certificate section certifying that the student completed the practical file. The file contains 10 programming questions and solutions related to Python programming and data science.

Uploaded by

Arnav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
901 views26 pages

Practical File Artificial Intelligence Class 10 For 2022-23 (Arnav Singh)

The document is a practical record file submitted for an Artificial Intelligence class. It includes an acknowledgement section thanking the teacher and school authorities. It also includes a certificate section certifying that the student completed the practical file. The file contains 10 programming questions and solutions related to Python programming and data science.

Uploaded by

Arnav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

A PRACTICAL RECORD FILE IS SUBMITTED FOR THE ARTIFICIAL INTELLIGENCE CLASS 10 SESSION

2022-23

Page 1
ACKNOWLEDGEMENT

I wish to express my deep sense of gratitude and


indebtedness to our learned teacher Sapna Rai ,
Indirapuram Public School Crossings Republic for
his invaluable help, advice and guidancein the
preparation of this project.

I am also greatly indebted to our principal


Ms. Renu Sharma and school authorities for providing
me with the facilities and requisite laboratory
conditions for making this practical file.

I also extend my thanks to a number of


teachers ,my classmates and friends who helped me to
complete this practical file successfully.

Arnav Singh (XB)

Page 2
CERTIFICATE

This is to certify that Arnav Singh

student of Class X, Indirapuram Public School,

Crossings Republik has completed the PRACTICAL

FILE during the academic year 2023-24 towards

partial fulfillment of credit for the ARTIFICIAL

INTELLIGENCE practical evaluation of 2023-24 and

submitted satisfactory

report, as compiled in the following pages, under my

supervision.

Internal Examiner External Examiner


Signature Signature

Date: School Seal PrincipalSignature

Page 3
Unit 3 Advanced Python
1. Write a program to compute the net run rate for a tournament.
#Enter details for team, for and against data
tn=input("Enter Team name:")
n=int(input("Enter no. of matches played:"))
#variables to store total scores and overs
tr=0
to=0
tagr=0
togr=0
#Entering runs and overs and adding them for n number of matches
for i in range(n):
r=int(input("Enter runs scored in match"+str(i+1)+":"))
o=int(input("Enter overs played:"))
tr=r+tr
to=to+o
agr=int(input("Enter runs conceded in match"+str(i+1)+":"))
ogr=int(input("Enter overs bowled:"))
tagr+=agr
togr+=ogr
#Computing the net runrate
nrr=(tr/to)-(tagr/togr)
#Displaying the net runrate
print("Net runrate is:",nrr)

Page 4
2. Write a program to check whether the given character is an uppercase letter or
lowercase letter or a digit or a special character.
#Input the character to check
ch=input("Enter Any Character:")
'''Checking whether it is upperletter or
lowerletter or digit or a special character'''
if ch.isupper():
print(ch, " is an upper case letter")
elif ch.isupper():
print(ch, " is a lower case letter")
elif ch.isdigit():
print(ch, " is a digit")
elif ch.isspace():
print(ch, " is a space")
else:
print(ch," is a special character")
3. Write a program to find the maximum number out of the given three numbers.
#Take input or three number to
comparen1=int(input("Enter the
Number1:")) n2=int(input("Enter the
Number2:")) n3=int(input("Enter the
Number3:"))
if n1>n2 and n1>n3:
print(n1, " - Number 1 is
greater")elif n1>n2 and n1>n3:
print(n2, " - Number 2 is
greater")elif n3>n1 and n3>n2:
print(n3, " - Number 3 is
greater")else:
print("All are same")

Page 5
4. An electric power distribution company charges its domestic consumers as follows
Consumption Units Rate of Charge
0-100 Rs. 1 per unit
101-300 Rs. 100 plus Rs. 1.25 per unit in excess of 100
301-500 Rs. 350 plus Rs. 1.50 per unit in excess of 300
500 and above Rs. 650 plus Rs. 1.75 per unit in excess of 500
Write a program that read the customer number & power consumed and prints the
amount to be paid by the customer. Note that output should be well formatted.
#Input Data
cno=int(input("Enter Cusumer Number:"))
pc=int(input("Enter power consumed:"))
#Computing bill amount based on power consumed
if pc>0 and pc<=100:
bill_amt=pc*1
elif pc>100 and pc<=300:
bill_amt=100+(pc-100)*1.25
elif pc>300 and pc<500:
bill_amt=350+(pc-300)*1.50
elif pc>500:
bill_amt=650+(pc-500)*1.75
else:
print("Invalid Power Consumed Units")
#Printing the bill in proper format
print("~"*60)
print("\t\tABC Power Company Ltd.")
print("~"*60)
print("Consumer Number:",cno)
print("Consumed Units:",pc)
print(" ")
print("Bill Amount:",bill_amt)
Page 6
#Enter a number to check
n=int(input("Enter number to check:"))
#Store the original number into temporary variable

s=0

r=n%10
s=s+(r**3)

print(s," is Armstrong number")


else:
print(s," is not an Artmstrong number")

5. Write a program to check whether the entered number is Armstrong or not.

6. Write a program to print a multiplication table of the entered number.

#Take input to accept a nmuber for printing Multiplication table

n=int(input("Enter number to print multiplication table:"))

#Take for loop for multiple

for i in range(1,11):

print(n," x ", i, " = ", n*i )

Page 7
7. Write a program to generate the following pattern:

2 3

4 5 6

7 8 9 10

11 12 13 14 15

#Take input for n lines

n=int(input("Enter n:"))

#Generating Pattern

k=1

for i in range(1,n+1):

for j in range(1,i+1):

print(k,end=" ")

k=k+1

print()

Page 8
8. Write a program to create a list of students' marks with user-defined values and
find the maximum.

#Take input for n lines

n=int(input("Enter no. of subjects:"))

#Creating empty list

l=[]

#Accepting marks and appending marks into the list

for i in range(n):

m=int(input("Enter marks:"))

l.append(m)

print("Maximum marks scored:",max(l)

9. Write a program to create a list of numbers and swap the content with the next value
divisible by 5.
For example: list = [4,25,31,7,35,44,55]
Output: [25,4,31,35,7,55,44]
#Take input for no of subjects
n=int(input("Enter no. of subjects:"))
#Creating empty list
l=[]
#Accepting marks and appending marks into the listfor i
in range(n):
m=int(input("Enter marks:"))
l.append(m) #Swaping
elements for i in
range(len(l)) :
if l[i] % 5 == 0 :
l [ i ], l [i-1] = l [ i - 1 ] , l [i]
print("List after swap:",l)
Page 9
10. Write a program to count the frequency of every element in a given list.

#Creating empty list

l = []

#Take input for n no. of elements

n=int(input("Enter the no. of elements:"))

#Append the values into the list

for i in range(n):

val=int(input("Enter value "+str(i+1)+":"))

l.append(val)

#Decalring a dictionary object to store the data

f = {}

for i in l:

if (i in f):

f[i] += 1

else:

f[i] = 1

#Displaying the data

for i, j in f.items():

print(i, "->", j)

Page 10
Unit 4 Data Science Programs
11. Write a program to create a 2D array using NumPy.

#import numpy package

import numpy as np

#Creating array using arange() function

arr=np.arange(5,45,5)

#reshaping array for 2D

arr=arr.reshape(2,4)

#printing array

print(arr)

12. Write a program to convert a python list to a NumPy array.

#Import NumPy Package


import numpy as np
#Creating empty list
l = []
#Take input for n no. of elements
n=int(input("Enter the no. of elements:"))
#Append the values into the list
for i in range(n):
val=int(input("Enter value "+str(i+1)+":"))
l.append(val)
#Converting list into numpy array
arr=np.array(l)
print("Array:",arr)

Page 11
13. Write a program to develop a matrix of 3x3 with values from 11 t0 28.

#import numpy package


import numpy as np
#Creating array using arange() function
arr=np.arange(11,28,2)
#reshaping array for 2D
arr=arr.reshape(3,3)
#printing array
print(arr)

14. Write a program to create a data frame to store data of candidates who appeared
in interviews. The dataframe columns are name, score, attempts, and qualify
(Yes/No). Assign rowindex as C001,C002, and so on.
#import pandas package

import pandas as pd

#Creating Dictionary to store data

d={'Name':['Anil','Bhavna','Chirag','Dhara','Giri'],

'Score':[25,20,22,23,21],

'Attempts':[1,2,2,1,1],

'Qualified':['Yes','No','Yes','Yes','No']} #Creating

a dataframe

df=pd.DataFrame(d,index=['C001','C002','C003','C004','C005'])

#Printing a dataframe

print(df)

Page 12
15. Write a program to create a dataframe named player and store their data in the
columns like team, no. of matches, runs, and average. Assign player name as row
index and Display only those player details whose score is more than 1000.
#Import package for Matplot Library

import matplotlib.pyplot as plt

#Creating lists for data

games=['Pubg', 'FreeFire', 'MineCraft', 'GTA-V','Call of duty', 'FIFA 22']

rating=[4.5,4.8,4.7,4.6,4.1,4.3]

#Creating bar graph with different bar colours

plt.bar(games,rating,color=['black', 'red', 'green', 'blue', 'yellow'])

#Customizing the bar graph

plt.title("Games Rating 2022")

plt.xlabel('Games')

plt.ylabel('Rating')

plt.legend();plt.show()

#Creating Dictionary to store data


d={'Team':['India','Pakistan','England','Asutralia'],
'Matches':[25,23,19,17],
'Runs':[1120,1087,954,830],
'Average':[44.80,47.26,50.21,48.82]}

16.#Displaying data whose


Write a program runs >the
to represent 1000
data on the ratings of mobile games on bar
chart. The sample data is given as: Pubg, FreeFire, MineCraft, GTA-V, Call of
duty, FIFA 22. The rating for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3.
Page 13
17. Consider the following data of a clothes store and plot the data on the line chart:
Month Jeans T-Shirts Shirts
March 1500 4400 6500
April 3500 4500 5000
May 6500 5500 5800
June 6700 6000 6300
July 6000 5600 6200
August 6800 6300 4500
Customize the chart as you wish.
#imort package for line chart
import matplotlib.pyplot as pp
#creating list data
mon =['March','April','May','June','July','August']
jeans= [1500,3500,6500,6700,6000,6800]
ts = [4400,4500,5500,6000,5600,6300]
sh = [6500,5000,5800,6300,6200,4500]
#Creating Line chart
pp.plot(mon,jeans,label='Mask',color='g',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='r')
pp.plot(mon,ts,label='Mask',color='b',linestyle='dashed', linewidth=4,\
marker='3', markerfacecolor='k', markeredgecolor='g')
pp.plot(mon,sh,label='Mask',color='r',linestyle='dashed', linewidth=4,\
marker='v', markerfacecolor='k', markeredgecolor='b')
#Cusotmizing plot
pp.title("Apna Garment Store")
pp.xlabel("Months")
pp.ylabel("Garments")
pp.legend()
pp.show()

Page 14
18. Observe the given data for monthly sales of one of the salesmen for 6 months. Plot
them on the line chart.

Month January February March April May June


Sales 2500 2100 1700 3500 3000 3800

Apply the following customizations to the chart:

 Give the title for the chart - "Sales Stats"


 Use the "Month" label for X-Axis and "Sales" for Y-Axis.
 Display legends.
 Use dashed lines with the width 5 point.
 Use red color for the line.
 Use dot marker with blue edge color and black fill color.

mon =['January','February','March','April','May','June']

pp.plot(mon,sales,label='Sales',color='r',linestyle='dashed',
linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='b')

pp.title("Sales Report")
pp.xlabel("Months")
pp.ylabel("Sales")
pp.legend()
pp.show()

Page 15
19. Write a menu-driven program to calculate the mean, mode and median for the
given data:

[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]

#import statistics
import statistics
#Creating list
l=[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
#Display mean, mode and median value using functions
print("Mean Value:%.2f"%statistics.mean(l))
print("Mode Value:%.2f"%statistics.mode(l))
print("Median Value:%.2f"%statistics.median(l))

20. Write a program to calculate variance and standard deviation for the given data:

[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

#import statistics

import statistics

#Creating list

l=[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

#Display varaince and standard deviation value using functions

print("Variance:%.2f"%statistics.variance(l))

print("Standard Deviation:%.2f"%statistics.stdev(l))

Page 16
Unit 5 Computer Vision
1. Visit this link (https://www.w3schools.com/colors/colors_rgb.asp). On the basis of
this online tool, try and write answers of all the below-mentioned questions.
o What is the output colour when you put R=G=B=255?
o What is the output colour when you put R=G=255,B=0?
o What is the output colour when you put R=255,G=0,B=255?
o What is the output colour when you put R=0,G=255,B=255?
o What is the output colour when you put R=G=B=0?
o What is the output colour when you Put R=0,G=0,B=255?
o What is the output colour when you Put R=255,G=0,B=0?
o What is the output colour when you put R=0,G=255,B=0?
o What is the value of your colour?
Solution:1.

White

Page 17
2. Yellow
3. Pink
4. Cyan
5. Black
6. Blue
7. Red
8. Green
9. R=0,G=0,B=255
22. Create your own pixels on piskelapp (https://www.piskelapp.com/) and make a
gif image.

Steps:
1. Open piskelapp on your browser.
2. Apply background for the picture.
3. Use pen to draw letter A
4. Copy the layer and paste it
5. Now erase letter A written previously
6. Apply the background colour for layer 2
7. Change the pen colour and Write I
8. Export the image.
9. Follow this link to access animated GIF: Click here

23. Do the following tasks in OpenCV.


a. Load an image and Give the title of the image
b. Change the colour of image and Change the image to grayscale
c. Print the shape of image
d. Display the maximum and minimum pixels of image
e. Crop the image and extract the part of an image
f. Save the Image

Page 18
1. Load Image and Give the title of image

#import required module cv2, matplotlib and numpy

import cv2

import matplotlib.pyplot as plt

import numpy as np

#Load the image file into memory

img = cv2.imread('octopus.png')

#Display Image

plt.imshow(img)

plt.title('Octopus')

plt.axis('off')

plt.show()

2. Change the colour of image and Change the image to grayscale


#import required module cv2, matplotlib and numpy
import cv2
import matplotlib.pyplot as plt
import numpy as np
#Load the image file into memory
img = cv2.imread('octopus.png')
#Chaning image colour image colour
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 19
3. Print the shape of image
import cv2
img = cv2.imread('octopus.png',0)
(1920, 1357)
print(img.shape)
4. Display the maximum and minimum pixels of image
import cv2
img = cv2.imread('octopus.png',0)
print(img.min()) 0
255
print(img.max())
5. Crop the image and extract the part of an image
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('octopus.png')
pi=img[150:400,100:200]
plt.imshow(cv2.cvtColor(pi, cv2.COLOR_BGR2RGB))
plt.title('Octopus')
plt.axis('off')
plt.show()
6. Save the Image
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('octopus.png')
plt.imshow(img)
cv2.imwrite('oct.jpg',img)
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 20
- Jupyter Codes and Practice:-
1:
k=[1]

import matplotlib.pyplot as yk

yk.plot(k)

yk.plot(1)

yk.plot("x-axis")

yk.plot("y-axis")

yk.show

2:
import statistics as st

datasets=[0,2,4,6]

x= st.mean(datasets)

print("mean is:", x)

x1= st.mode(datasets)

print("Mode is:" , x)

x2= st.median(datasets)

print("Median is:", x)

x3= st.stdev(datasets)

print("Standard Deviation is:", x)

import matplotlib.pyplot as mat

from matplotlib import pyplot as plt

plt.plot(datasets)

plt.plot ylabel("y axis")

plt.plot xlabel("x axis")

plt.show()
Page 21

3:
from matplotlib import pyplot as plt

x=[5,5,8]

y=[1,4,2]

plt.plot(x)

plt.plot(y)

plt.show()

from matplotlib import pyplot as plt

players['Virat','Dhoni']

runs=[92,105]

plt.bar

4:
import numpy as np

import matplotlib.pyplot as plt

X = ['Group A','Group B','Group C','Group D']

Ygirls = [10,20,20,40]

Zboys = [20,30,25,30]

X_axis = np.arange(len(X))

plt.bar(X_axis - 0.2, Ygirls, 0.4, label = 'Girls')

plt.bar(X_axis + 0.2, Zboys, 0.4, label = 'Boys')

plt.xticks(X_axis, X)

plt.xlabel("Groups")

plt.ylabel("Number of Students")

plt.title("Number of Students in each group")

plt.legend()

plt.show()

import matplotlib.pyplot as plt

x1 = [89, 43, 36, 36, 95, 10,


66, 34, 38, 20]
y1 = [21, 46, 3, 35, 67, 95,
53, 72, 58, 10]

x2 = [26, 29, 48, 64, 6, 5,


36, 66, 72, 40]

y2 = [26, 34, 90, 33, 38, Page 22


20, 56, 2, 47, 15]

plt.scatter(x1, y1, c ="pink",


linewidths = 2,
marker ="s",
edgecolor ="green",
s = 50)

plt.scatter(x2, y2, c ="yellow",


linewidths = 2,
marker ="^",
edgecolor ="red",
s = 200)

plt.xlabel("X-axis")

plt.ylabel("Y-axis")

plt.show()

5:
import warnings

warnings.filterwarnings (import numpy as np

import pandas as pd

import matplotlib.pyplot

from sklearn.neighbors import KNeighborsClassifier

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import train_test_split

data={'Height':(158,158,158,160,160,163,163,163,163,165,165,165,168,168,168,170,170,170),
'Weight':(58,59,63,59,60,60,61,64,64,61,62,65,62,63,66,63,64,68),'T-
Shirt':('M','M','M','M','M','M','M','L','L','L','L','L','L','L','L','L','L','L')}

df=pd.DataFrame(data)

print(df)

confusion_matrix(y_test, prediction)

array([[4, 0],

[1, 3]], dtype=int64)

Height1 = int(input())

Weight1 = int(input())

Output= knn.predict(n)

Height1 = int(input())
Weight1 = int(input())

n = np.array([Height1, Weight1])

n = n.reshape(-1, 2)
Page 23
prediction1 = knn.predict(n)

print(prediction1)

6:
import numpy as np

import matplotlib.pyplot as plt

import numpy as np

import matplotlib.pyplot as plt

X_axis = np.arange(len(X))

plt.bar(X_axis - 0.2, Ygirls, 0.4, label = 'Girls')

plt.bar(X_axis + 0.2 , Zboys, 0.4, label = 'Boys')

plt.xticks(X_axis, X)

plt.xlabel("Groups")

plt.ylabel("Number of Students")

plt.title("Number of Students in each group")

plt.legend()

plt.show()

x1 = [89, 43, 36, 36, 95, 10,


66, 34, 38, 20]

y1 = [21, 46, 3, 35, 67, 95,


53, 72, 58, 10]

x2 = [26, 29, 48, 64, 6, 5,


36, 66, 72, 40]

y2 = [26, 34, 90, 33, 38,


20, 56, 2, 47, 15]

plt.scatter(x1, y1, c ="pink",


linewidths = 2,
marker ="s",
edgecolor ="green",
s = 50)

plt.scatter(x2, y2, c ="yellow",


linewidths = 2,
marker ="^",
edgecolor ="red",
s = 200)
plt.xlabel("X-axis")

plt.ylabel("Y-axis")

plt.show()

Page 24

You might also like