PRATHIk
PRATHIk
Science
& Computer Vision
A PRACTICAL FILE
SUBMITTED TO
NATIONAL MODEL SENIOR SECONDARY SCHOOL
AFFILIATED TO CBSE FOR THE AISSCE 2024
BY
PRATHIK VASUDEVAN
UNDER THE GUIDANCE OF
Ms. A.J. ANU JACOB
NATIONAL MODEL
1
SENIOR SECONDARY SCHOOL
JANUARY
2024
CERTIFICATE
2
Seal
3
DECLARATION
I hereby declare that the Practical File for the topics ,
Advanced Python, Data Science and Computer Vision is
submitted to the Department of Artificial Intelligence of
National Model Senior Secondary School, Peelamedu,
Coimbatore is a bonafide work of me.
REGISTER NUMBER
4
ACKNOWLEDGEMENT
5
6
CONTENTS
No Practical Date Signature
1 Unit 3 Advanced Python Programs
1 Write a program to compute the net run rate for a tournament.
2 Write a program to check whether the given character is an
uppercase letter or lowercase letter or a digit or a special
character.
3 Write a program to find the maximum number out of the given
three numbers.
4 An electric power distribution company charges its domestic
consumers as follows:
AI Practical file
No Practical Date Signature
8 Write a program to create a list of students' marks with user-
defined values and find the maximum.
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]
10 Write a program to count the frequency of every element in a
given list.
2 Unit 4 Data Science Programs
11 Write a program to create a 2D array using NumPy.
12 Write a program to convert a python list to a NumPy array.
13 Write a program to create a dataframe named new_frame of class
averages of different subjects () for premidterm and midterm
examination and store the data in the columns ‘premidterm’ and
‘midterm’. Assign subject names as row index and Display the
frame
14 Write a program to represent the data the data frame created in
previous question on bar chart (xlabel=subjects,ylabel=class
average).create subplots for ‘premidterm’ and ‘midterm’
AI Practical file
No Practical Date Signature
3 Unit 5 Computer Vision
17 Visit 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.
What is the output colour when you put R=G=B=255?
What is the output colour when you put R=G=255,B=0?
What is the output colour when you put R=255,G=0,B=255?
What is the output colour when you put R=0,G=255,B=255?
What is the output colour when you put R=G=B=0?
What is the output colour when you Put R=0,G=0,B=255?
What is the output colour when you Put R=255,G=0,B=0?
What is the output colour when you put R=0,G=255,B=0?
What is the value of your colour?
AI Practical file
1. Write a program to compute the net run rate for a tournament.
Code:
tn=input("Enter Team name:")
n=int(input("Enter no. of matches played:"))
to=0 #variable to store total overs played
tr=0 #variable to store total runs
tagr=0 #variable to store total runs
conceded togr=0 #variable to store total
overs bowled for i in range(n):
r=int(input("Enter runs scored in match"+str(i+1)+":"))
o=int(input("Enter overs played:"))
tr=tr+r
to=to+o
agr=int(input("Enter runs conceded in match"+str(i+1)+":"))
ogr=int(input("Enter overs bowled:"))
tagr+=agr
togr+=ogr
nrr=(tr/to)-(tagr/togr) #to find the net run
rate print("Net runrate is:",nrr)
Code:
AI Practical file
3. Write a program to find the maximum number out of the given three
different numbers.
AI Practical file
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"))
print("\t\tABC Power Company Ltd.")
print("~"*60)
print("Consumer Number:",cno)
print("Consumed Units:",pc)
print(" ")
print("Bill Amount:",bill_amt)
while n!=0:
r=n%10
s=s+(r**3)
n//=10
#Checking & displaying whether armstrong or not
if t==s:
print(s," is Armstrong number")
else:
print(s," is not an Artmstrong number")
AI Practical file
6. Write a program to print a multiplication table of the entered number.
for i in range(1,11):
4 5 6
7 8 9 10
11 12 13 14 15
AI Practical file
8. Write a program to create a list of students' marks with user-defined
values andfind the maximum.
list1=[]
for i in range(n):
m=int(input("Enter marks:"))
list1.append(m)
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]
AI Practical file
Unit 4 Data Science Programs
11. Write a program to create a 2D array using NumPy.
import numpy as np
arr=np.arange(5,45,5)
arr=arr.reshape(2,4)
#printing array
print(arr)
AI Practical file
13. Write a program to create a dataframe named new_frame of class averages
of different subjects () for premidterm and midterm examination and store the
data in the columns ‘premidterm’ and ‘midterm’. Assign subject names as row
index and Display the frame prem idterm midterm
sst 70 70
maths 68 69
import pandas as pd Sci 71 70
#Creating lists for data 2lang
Eng
75
73
75
73
subjects=['sst', 'maths', 'Sci', '2lang','Eng', 'AI'] AI 70 74
14.Write a program to represent the data the data frame created in previous question
on bar chart (xlabel=subjects,ylabel=class average).create subplots for ‘premidterm’
and ‘midterm’.
import matplotlib.pyplot as
plt import pandas as pd
#Creating lists for data
subjects=['sst', 'maths', 'Sci', '2lang','Eng', 'AI']
# for MIDTERM
plt.subplot(1, 2, 2)
AI Practical file
plt.bar(subjects,clas_avg['midterm'],color=['black', 'red', 'green', 'blue',
'yellow','orange'])
plt.xlabel('subjects')
plt.ylabel('Class Average')
plt.title('midterm')
15. Write a program to calculate the mean, mode and median for
thegiven data: [5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
import statistics
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))
OR
import numpy as np
import statistics as st
array1 = np.array([5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4])
print(array1)
AI Practical file
16. 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]
print("Variance:%.2f"%statistics.variance(l))
print("Standard Deviation:%.2f"%statistics.stdev(l))
AI Practical file
What is the value of your colour?
Solution:1.
1. White
AI Practical file
1. Load Image and Give the title of image
import cv2
import numpy as np
img = cv2.imread('octopus.png')
#Display Image
plt.imshow(img)
plt.title('Octopus')
plt.axis('off')
plt.show()
AI Practical file
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
print(img.max()) 255
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()
AI Practical file