X_LABPGMS_24_25
X_LABPGMS_24_25
X_LABPGMS_24_25
Note:
Write the program in right side and output in the left side page (Plain page)
2. Write a python program to input the lengths of the three sides of a triangle and display
3. Write a python program to input a number and display whether it is a palindrome or not.
12.Write a Python program that accepts a word from the user and reverse it.
14. Write a python program to plot a scatter plot with different shape and colour for two
datasets.
15. Write a python program to import a image and Access Image Properties.
1. Write a program in python to print the multiplication table of a no.
CODE:
num = 12
print(num,'x',i,'=',num*i)
else:
print("Invalid Input")
OUTPUT:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
2. Write a python code to input the lengths of the three sides of a triangle and
display whether a triangle will be scalene, isosceles or equilateral triangle.
CODE:
elif a == b or b == c or a==c:
else :
OUTPUT
CODE:
num=int(input("Enter a number:"))
temp=num
rev=0
while(num>0):
d=num%10
rev=rev*10+d
num=num//10
if(temp==rev):
else:
print("Not a palindrome!")
OUTPUT
Enter a number:2001002
CODE:
If n<= 0:
elif n == 1:
print(n1)
else:
print(n1,end=' ')
n3 = n1 + n2
n1 = n2
n2 = n3
count += 1
OUTPUT:
Fibonacci sequence:
8
5. Write a Python program to find the sum of natural numbers up to n where n is
provided by user.
CODE:
else: sum = 0
while(num> 0):
OUTPUT
Enter a number: 16
CODE:
OUTPUT:
CODE:
si=p*t*r/100
x=(1+r/100)**t
CI= p*x-p
OUTPUT:
CODE:
List=[10,30,50,20,40]
Tuple=(10,50,30,40,20)
print ('Length:',len(List))
print ('Length:',len(Tuple))
print("List:",List[1:3])
print("Tuple:",Tuple[:4])
Length: 5
Length: 5
max of List: 50
max of Tuple: 50
min of List: 10
min of Tuple: 10
9. Write a program to find out the maximum and minimum element from the list.
CODE:
l = max_min [0]
s = max_min [0]
if num> l:
l = num elifnum< s:
s = num
OUTPUT:
CODE:
print(word[char], end="")
print("\n")
OUTPUT:
11. Write a python code using Numpy package creating an array of 5 subject marks
and display the average of all marks.
CODE:
import numpy as np
import statistics
a = np.array([95,90,49,71,80])
m = statistics.mean(a)
OUTPUT
The average is : 77
12. Write a python program to create a list of distance travelled by a car in a week
and calculate using statistics module(Mean,Median,Mode).
CODE:
import statistics
d=[45,48,50,49,46,90,41]
m1=statistics.mean(d)
m2= statistics.median(d)
m3= statistics.mode(d)
OUTPUT:
The median is : 48
The mode is : 45
CODE:
#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
#RGB
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
#GRAYSCALE
#plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
#HSV_Hue,Saturation,value
#plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
plt.title('Octopus')
plt.axis('off')
plt.show()
OUTPUT:
RGB
GRAYSCALE
HSV
14. Write a python program to plot a scatter plot with different shape and
colour for two datasets.
CODE:
import matplotlib.pyplot as plt
# dataset-1
x1 = [89, 43, 36, 36, 95, 10, 66, 34, 38, 20]
y1 = [21, 46, 3, 35, 67, 95, 53, 72, 58, 10]
# dataset2
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()
OUTPUT:
15. Write a python program to import a image and Access Image
Properties.
CODE:
# Importing the OpenCV Module
import cv2 as cv
# Reading the image using imread() function
img = cv.imread('D:\octopus.jpg')
dimensions = img.shape
#Accessing height, width and channels
# Height of the image
height = img.shape[0]
# Width of the image
width = img.shape[1]
# Number of Channels in the Image
channels = img.shape[2]
# Displaying the dimensions of the Image
print("Dimension are :",dimensions)
print("Height :",height,"px")
print("Width :",width,"px")
print("Number of Channels : ",channels)
OUTPUT:
Dimension are : (510, 474, 3)
Height : 510 px
Width : 474 px
Number of Channels : 3