0% found this document useful (0 votes)
31 views13 pages

X_LABPGMS_24_25

Python

Uploaded by

ksasikrishna
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)
31 views13 pages

X_LABPGMS_24_25

Python

Uploaded by

ksasikrishna
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/ 13

JAI GURU DEV

MAHARISHI VIDYA MANDIR SR. SEC. SCHOOL,CHETPET,CHENNAI - 31


CLASS X PYTHON RECORD PROGRAMS 2024-2025

Note:

Write the program in right side and output in the left side page (Plain page)

1. Write a program in python to print the multiplication table of a no.

2. Write a python program to input the lengths of the three sides of a triangle and display

whether triangle will be scalene, isosceles or equilateral triangle.

3. Write a python program to input a number and display whether it is a palindrome or not.

4. Write a Program to display the Fibonacci sequence up to n th term where n is provided


by the user.
5. Write a Python program to find the sum of natural numbers up to n where n is provided
by user.
6. Write a program to count and display the number of vowels, consonants, uppercase,
lowercase characters in string.
7. Write a program to calculate Simple Interest and compound interest.

8. Write a python program to perform List and Tuple operations.


9. Write a program to find out the maximum and minimum element from the list.
10. Write a python program, using Numpy package creating an array of 5 marks and
display the average of all marks.
11. 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).

12.Write a Python program that accepts a word from the user and reverse it.

13. Write a python program to change the colour of image .

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

num = int(input("Display multiplication table of? "))

for i in range(1, 11):

print(num,'x',i,'=',num*i)

else:
print("Invalid Input")

OUTPUT:

Display multiplication table of? 5

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:

print(“The sides of the triangle")

a = int(input("Enter first side : "))

b = int(input("Enter second side : "))

c = int(input("Enter third side : "))

if a == b and b == c and a==c:

print("Type of triangle:Equilateral Triangle")

elif a == b or b == c or a==c:

print("Type of triangle:Isosceles Triangle")

else :

print("Type of triangle:Scalene Triangle")

OUTPUT

Input the sides of the triangle :

Enter first side : 5

Enter second side : 6

Enter third side : 4

Type of triangle:Scalene Triangle


3. Write a python program to input a number and display whether it is a palindrome
or not.

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

print("The number is palindrome!")

else:

print("Not a palindrome!")

OUTPUT

Enter a number:2001002

The number is palindrome!


4. Write a Program to display the Fibonacci sequence up to nth term where n is
provided by the user.

CODE:

n = int(input("How many terms? "))

# first two terms n1 = 0 n2 = 1 count = 0

# check if the number of terms is valid

If n<= 0:

print("Please enter a positive integer")

elif n == 1:

print("Fibonacci sequence upto",n,":")

print(n1)

else:

print (n1,n2, end=’ ‘)

print("Fibonacci sequence upto",n,":")

while count <n:

print(n1,end=' ')

n3 = n1 + n2

n1 = n2

n2 = n3

count += 1

OUTPUT:

How many terms? 7

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:

num = int(input("Enter a number: "))

if num< 0: print("Enter a positive number")

else: sum = 0

# use while loop to iterate un till zero

while(num> 0):

sum += num num -= 1

print("The sum is",sum)

OUTPUT

Enter a number: 16

The sum is 136

6. Write a program to count and display the number of vowels, consonants,


uppercase, lowercase characters in string.

CODE:

txt = input("Enter Your String : ")


v = c = uc = lc = 0
v_list = ['a','e','i','o','u']
for i in txt:
if i in v_list:
v += 1
if i not in v_list:
c += 1
ifi.isupper():
uc += 1
ifi.islower():
lc += 1
print("Number of Vowels in this text = ", v)

print("Number of Consonants in this text = ", c)

print("Number of Uppercase letters in this text=", uc)

print("Number of Lowercase letters in this text=", lc)

OUTPUT:

Enter Your String : Hello


Number of Vowels in this text = 2
Number of Consonants in this text = 3
Number of Uppercase letters in this text= 1
Number of Lowercase letters in this text= 4
7. Write a program to calculate Simple Interest and compound interest.

CODE:

p=float(input("Enter the principal amount : "))

r=float(input("Enter the rate of interest : "))

t=float(input("Enter the time in years : "))

si=p*t*r/100

x=(1+r/100)**t

CI= p*x-p

print("Simple interest is : ", round(si,2))

print("Compound interest is : ", round(CI,2))

OUTPUT:

Enter the principal amount : 1000

Enter the rate of interest : 12

Enter the time in years : 5

Simple interest is : 600.0

Compound interest is : 762.34

8. Write a python program to perform List and Tuple operations.

CODE:

List=[10,30,50,20,40]

Tuple=(10,50,30,40,20)

print ('Length:',len(List))

print ('Length:',len(Tuple))

print ('max of List:', max(List))

print ('max of Tuple:', max(Tuple))

print ('min of List:', min(List))

print ('min of Tuple:', min(Tuple))

print ('sum of List:', sum(List))

print ('sum of Tuple:', sum(Tuple))

print("List:",List[1:3])

print("Tuple:",Tuple[:4])

print ('List in sorted order:', sorted(List))

print ('Tuple in sorted order:', sorted(Tuple))


OUTPUT

Length: 5

Length: 5

max of List: 50

max of Tuple: 50

min of List: 10

min of Tuple: 10

sum of List: 150

sum of Tuple: 150

List: [30, 50]

Tuple: (10, 50, 30, 40)

List in sorted order:[10, 20, 30, 40, 50]

Tuple in sorted order:[10, 20, 30, 40, 50]

9. Write a program to find out the maximum and minimum element from the list.

CODE:

max_min=[0, 10, 15, 40, -5, 42, 17, 28, 75]

l = max_min [0]

s = max_min [0]

for num in max_min:

if num> l:

l = num elifnum< s:

s = num

print(‘The maximum number is:’,l)

print(‘The minimum number is:’, s)

OUTPUT:

The maximum number is: 75

The minimum number is: -5


10. Write a Python program that accepts a word from the user and reverse it.

CODE:

word = input("Input a word to reverse: ")

for char in range(len(word) - 1, -1, -1):

print(word[char], end="")

print("\n")

OUTPUT:

Input a word to reverse: HELLO

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)

print('The average is :',m)

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)

print(“The mean is :”,m1)

print(“The median is :”,m2)

print(“The mode is :”,m3)

OUTPUT:

The mean is : 52.714285714285715

The median is : 48

The mode is : 45

13. Write a python program to change the colour of image .

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

You might also like