0% found this document useful (0 votes)
15 views22 pages

PRATHIk

The document is a practical file submitted by Prathik Vasudevan to the National Model Senior Secondary School for the subject of Artificial Intelligence, covering topics in Advanced Python, Data Science, and Computer Vision. It includes a certificate of completion, a declaration of originality, acknowledgments, and a detailed table of contents listing various programming tasks and projects. The practical file contains code examples and explanations for each task, demonstrating the student's understanding and application of the subjects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views22 pages

PRATHIk

The document is a practical file submitted by Prathik Vasudevan to the National Model Senior Secondary School for the subject of Artificial Intelligence, covering topics in Advanced Python, Data Science, and Computer Vision. It includes a certificate of completion, a declaration of originality, acknowledgments, and a detailed table of contents listing various programming tasks and projects. The practical file contains code examples and explanations for each task, demonstrating the student's understanding and application of the subjects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Advanced Python, Data

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

This is to certify that PRATHIK VASUDEVAN of class


X – CLASS INDIAN has prepared the Practical File on
Advanced Python , Data Science and Computer Vision.
This Practical File is the result of his/her efforts and
endeavors. This file is found worthy of acceptance as the
final Practical File for the subject Artificial Intelligence.

Countersigned Signature of the Staff


Head of the Institution

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.

SIGNATURE OF THE STUDENT

NAME OF THE STUDENT

CLASS AND SECTION

REGISTER NUMBER

4
ACKNOWLEDGEMENT

I would like to express my sincere thanks and gratitude to


my teacher Ms.A.J.Anu Jacob as well as our beloved
Principal Mrs.D. Geetha who gave me the golden
opportunity, support and guidance to complete this
Practical File. Secondly, I would also like to thank my
parents and friends who helped me a lot in finishing this
Practical File within the limited time.

Thanks again to all who helped me.

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:

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.
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.
7 Write a program to generate the following pattern:
1
2 3
4 5 6
7 8 9 10

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’

15 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]
16 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]

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?

18 Do the following tasks in OpenCV.


 Load an image & Give the title of the image
 Change the image to grayscale
 Print the shape of image
 Display the maximum and minimum pixels of image
 Crop the image.
 Save the Image

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)

2. Write a program to check whether the given character is an uppercase letter or


lowercase letter or a digit or a special character.

Code:

#Input the character to check


ch=input("Enter Any Character:")
if ch.isupper():
print(ch, " is an upper case letter")
elif ch.islower():
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")

AI Practical file
3. Write a program to find the maximum number out of the given three
different numbers.

#Take input or three number to compare


n1=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 n2>n1 and n2>n3:


print(n2, " - Number 2 is greater")
elif n3>n1 and n3>n2:
print(n3, " - Number 3 is greater")
else:
print("All are same")

4. An electric power distribution company charges its domestic consumers as follows.


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.
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
501 and above Rs. 650 plus Rs. 1.75 per unit in excess of 500
#Input Data
cno=int(input("Enter Consumer Number:"))

pc=int(input("Enter 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

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)

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


n=int(input("Enter number to check:"))
#Store the original number into temporary variable
t=n
s=0
#Computing the sum of cube of each digit and iterating until n=0

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.

#Take input to accept a number 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 )

7. Write a program to generate the following 1


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("\n")
print()

AI Practical file
8. Write a program to create a list of students' marks with user-defined
values andfind the maximum.

#Take input for n lines

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

#Creating empty list

list1=[]

#Accepting marks and appending marks into the list

for i in range(n):

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

list1.append(m)

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

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
list1=[]
#Accepting marks and appending marks into the
list
for i in range(n):
m=int(input("Enter marks:"))
list1.append(m)
#Swaping elements
for i in range(len(list1)) :
if list1[i] % 5 == 0 :
list1[ i ], list1[i-1] = list1[ i - 1 ] , list1[i]
print("List after swap:",list1)
AI Practical file
10. Write a program to count the frequency of every element in a given list.

#Creating empty list


list1 = []
#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)+":"))
list1.append(val)
#Decalring a dictionary object to store the
data f = {} #Initially dictionary will be empty
print(f) #to check the dictionary
for i in list1:
if (i in f):
f[i] += 1
else:
f[i] = 1
print(f)
print(f.items()) #to check the index and value inside the
dictionary #Displaying the data
for i, j in f.items():
print(i, "->", j)

AI Practical file
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)

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

#creating a dictionary with class averages clas_avg={'premidterm':


[70,68,71,75,73,70],'midterm':[70,69,70,75,73,74]}

#Creating data frame with the given data


newframe=pd.DataFrame(clas_avg,index=subjects)
print(newframe)

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']

#creating a dictionary with class averages clas_avg={'premidterm':


[70,68,71,75,73,70],'midterm':[70,69,70,75,73,74]}

#Creating data frame with the given data


newframe=pd.DataFrame(clas_avg,index=subjects)
print(newframe)

#Creating bar graph with different bar colours


# for PRE MIDTERM
plt.subplot(1, 2, 1)
plt.bar(subjects,clas_avg['premidterm'],color=['black','red','green','blue','yellow','orange
'])
plt.xlabel('subjects')
plt.ylabel('Class Average')
plt.title('premidterm')

# 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)

print("\nMean: ", np.mean(array1))

print("\nMedian: ", np.median(array1))

print("\nMode: ", st.mode(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]

#Display varaince and standard deviation value using functions

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

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

Unit 5 Computer Vision


17.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.
 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?

AI Practical file
 What is the value of your colour?

Solution:1.
1. White

18.Do the following tasks in OpenCV.


 Load an image & Give the title of the image
 Change the image to grayscale
 Print the shape of image
 Display the maximum and minimum pixels of image
 Crop the image.
 Save the Image

AI Practical file
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()

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

You might also like