PYTHON - Record Programs
PYTHON - Record Programs
KOLAZHY- THRISSUR
SKILL EDUCATION
(ARTIFICIAL INTELLIGENCE-417)
PRACTICAL RECORD
Name :___________________________________________________
___________________________________________________________
_______________________________________________________________
1|Page
INDEX
SL DATE CONTENTS PAGE
NO NO
2|Page
Advance Python Programs
#1 WAP to accept Name and 5 Marks of a student and find and print the
Total marks and Average marks.
Program code
Name = input(“Enter Name of the Student=”)
M1 = float (input(“Enter the English Marks = “))
M2 = float (input(“Enter the Hindi Marks = “))
M3 = float (input(“Enter the Language Marks = “))
M4 = float (input(“Enter the Science Marks = “))
M5 = float (input(“Enter the Social Science Marks = “))
Total = M1+M2+M3+M4+M5
Avg=Total/5
print(“ Student Name = “,Name)
print(“ Total Marks =”,Total)
print(“Average Marks =”,Avg)
Output
Enter Name of the Student=Mahesh
Enter the English Mark=27
Enter the Hindi Mark = 32
Enter the Language Mark =45
Enter the Science Mark = 39
Enter the Social Science Mark =41
3|Page
#2 WAP to calculate the Area and Perimeter of a Square ( A= S*S , P = 4*S )
Program code
S = float (input(“Enter Side = “))
print(“Area of Square =”, S*S)
print (“Perimeter of a Square=”, 4*S)
Output
Enter Side =15
Area of Square =225
Perimeter of a Square=60
*******
#3 WAP to accept any Character and check whether it’s an special symbol,
Number, Uppercase character or Lowercase character .
Program Code
ch=input("Enter a Character:")
if ch>='A' and ch<='Z':
print ("You have entered a Upper case Character")
elif ch>='a' and ch<='z':
print ("You have entered a Lower case Character ")
elif ch>='0' and ch<='9':
print ("You have entered a Number")
else:
print("You have entered a Special symbol")
Output
Case 1 Case 2
Enter a Character:1 Enter a Character: q
You have entered a Number You have entered a Lower case Character
Case 3 Case 4
Enter a Character: Q Enter a Character: /
You have entered a Upper case Character You have entered a Special symbol
***********
4|Page
#4 WAP to print the multiplication table of a number.
Program Code
N=int(input("Enter the No="))
i=1
while(i<=10):
print (i,"*",N,"=",i*N)
i=i+1
print("End of Loop")
Output
Enter the No=7
1*7=7
2 * 7 = 14
.
.
.
9 * 7 = 63
10 * 7 = 70
End of Loop
*************
5|Page
Data Science Programs
Output
6|Page
#2 WAP to read an open csv file “JaipurFinalCleanData.csv” and sort first
two rows based on mean temperature in ascending order and date in
descending order .
Program Code
import pandas as pd
dataframe = pd.read_csv("JaipurFinalCleanData.csv")
jaipur_weather=dataframe.sort_values(by='meantempm',ascending=True)
print(jaipur_weather.head(2))
date=dataframe.sort_values(by='date',ascending=False)
print(date.head(5))
Output
date meantempm maxtempm ... precipm_1 precipm_2 precipm_3
252 2017-01-11 10 18 ... 0.0 0.0 0.0
253 2017-01-12 12 19 ... 0.0 0.0 0.0
[2 rows x 40 columns]
date meantempm maxtempm ... precipm_1 precipm_2 precipm_3
675 2018-03-11 26 34 ... 0.0 0.0 0.0
674 2018-03-10 26 34 ... 0.0 0.0 0.0
673 2018-03-09 26 33 ... 0.0 0.0 0.0
672 2018-03-08 24 32 ... 0.0 0.0 0.0
671 2018-03-07 24 32 ... 0.0 0.0 0.0
[5 rows x 40 columns]
7|Page
#3 WAP to draw a line chart using matplotlib library .
Program Code
import matplotlib.pyplot as plt
import numpy as np
marks=np.array([70,85,65,90,95])
subjects=["English","Maths", "Science","Social Science" , "AI"]
plt.plot(subjects,marks,color="r", marker="*",markeredgecolor="blue")
plt.xlabel("Subject Names" ,fontsize=14)
plt.ylabel("Marks" , fontsize=14)
plt.title("Line Graph of Student's Performance")
plt.show()
Output
8|Page
#4 WAP to draw a bar chart using matplotlib library .
Program Code
import matplotlib.pyplot as plt
import numpy as np
marks=np.array([70,85,65,90,95])
subjects=["English","Maths", "Science","Social Science" , "AI"]
plt.bar(subjects,marks,color=["orange","red","blue","yellow","green"])
plt.xlabel("Subject Names" ,fontsize=14)
plt.ylabel("Marks" , fontsize=14)
plt.title("Bar Graph of Student's Performance")
plt.show()
Output
9|Page
#5 WAP to draw a pie chart using matplotlib library .
Program Code
import matplotlib.pyplot as plt
import numpy as np
marks=np.array([70,85,65,90,95])
subjects=["English","Maths", "Science","Social Science" , "AI"]
colors=["orange","red","blue","yellow","green"]
explode=[0,0,0,0,0.2]
plt.pie(marks,labels=subjects,colors=colors,explode=explode,shadow=True)
plt.title("Pie Chart of Student's Performance")
plt.show()
Output
10 | P a g e
Computer Vision Programs
#1 WAP to store the pixel values in the Numpy array and to display image
using opencv cv2 library .
Program Code
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flower.png")
plt.imshow(img)
plt.title("Image")
plt.axis('off')
plt.show()
Output
11 | P a g e
#2 WAP to store the pixel values in the Numpy array and to display image
using opencv cv2 library in RGB format.
Program Code
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flower.png")
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title("Image")
plt.axis('off')
plt.show()
Output
12 | P a g e
#3 WAP to store the pixel values in the Numpy array and to display image
using opencv cv2 library as a gray scale image.
Program Code
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flower.png",0)
plt.imshow(img,cmap='gray',interpolation='bicubic')
plt.title("Image")
plt.axis('off')
plt.show()
Output
13 | P a g e
#4 WAP to display minimum and maximum pixel value present in the image
using opencv cv2 library .
Program Code
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flower.png")
print("Minimum pixel value = ",img.min())
print("Maximum pixel value = ",img.max())
Output
14 | P a g e
#5 WAP to crop the image using opencv cv2 library .
Program Code
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("flower.png")
roi=img[10:425,10:425]
plt.imshow(cv2.cvtColor(roi,cv2.COLOR_BGR2RGB))
plt.title("Cropped Image")
plt.axis('off')
plt.show()
Output
15 | P a g e