You are on page 1of 59

SRIMATHI SUNDARAVALLI MEMORIAL SCHOOL

NEW PERUNGALATHUR, CHENNAI - 600 063

CLASS XI
COMPUTER SCIENCE RECORD
2022 - 2023
SRIMATHI SUNDARAVALLI MEMORIAL SCHOOL
NEW PERUNGALATHUR, CHENNAI - 600 063

BONAFIDE CERTIFICATE

Certified that this COMPUTER SCIENCE Record is the

bonafide work of__________________________________________________________

ROLL No.: ______________________ of Class XI, under my supervision and

guidance.

PRINCIPAL TEACHER INCHARGE

Submitted for evaluation during the ANNUAL Practical Examination

2022-2023 held on _____________________.


INDEX

S.NO. DATE PROGRAM NAME PAGE NO.

1. SIMPLE INTEREST AND COMPOUND INTEREST 1

2. GREATEST OF THE 3 NUMBERS 2

3. ELECTRICITY BILL CALCULATION 3

4. AREA OF DIFFERENT SHAPES 4

5. SUM OF THE SERIES 6

6. PRIME NUMBERS BETWEEN 1 AND N 7

7. CHECK THE NUMBER TYPE 8

8. TRIANGLE PATTERN - I 10

9. TRIANGLE PATTERN – II 13

10. STRING MANIPULATIONS – I 16

11. STRING MANIPULATIONS – II 19

12. STRING MANIPULATIONS – III 21

13. LIST OPERATIONS - I 24

14. LIST OPERATIONS - II 26

15. LIST OPERATIONS – III 29

16. LIST OPERATIONS - IV 32

17. TUPLE OPERATIONS – I 35

18. TUPLE OPERATIONS – II 38

19. DICTIONARY OPERATIONS - I 41

20. DICTIONARY OPERATIONS - II 44

21. DICTIONARY OPERATIONS – III 47

22. PYTHON MODULES 51

23. NUMBER CONVERSIONS 55

SIGNATURE OF THE TEACHER


SSM SCHOOL PROGRAM MANUAL

PGM.NO:1 SIMPLE INTEREST AND COMPOUND INTEREST


DATE:

AIM:

To write a Python program to calculate the simple interest and


compound interest for the given principal, rate of interest and number of years.

SOURCE CODE:

p=float(input("Enter the Principal:"))


n=int(input("Enter the no.of years:"))
r=float(input("Enter the rate of interest:"))
si=(p*n*r)/100
ci=p*(pow(1+r/100,n)-1)
print("Simple Interest=",si,"\nCompound Interest=",ci)

INPUT/OUTPUT:

Enter the Principal:1000


Enter the no.of years:3
Enter the rate of interest:12
Simple Interest= 360.0
Compound Interest= 404.92

RESULT:

Thus the program is executed successfully.

Page 1 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO:2 GREATEST OF THE 3 NUMBERS

DATE:

AIM:

To write a Python program to find the greatest of the three numbers.

SOURCE CODE:

print("Enter three numbers: ")


a=int(input(“A? ”))
b=int(input(“B? ”))
c=int(input(“C? ”))
if(a>b):
if(a>c):
print(a," is the greatest of three numbers")
else:
print(c," is the greatest of three numbers")
else:
if(b>c):
print(b," is the greatest of three numbers")
else:
print(c," ids the greatest of three numbers")

INPUT/OUTPUT:

Enter three numbers:


A? 4
B? 7
C? 5
7 is the greatest of three numbers

RESULT:
Thus the program is executed successfully.
Page 2 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO:3 ELECTRICITY BILL CALCULATION

DATE:

AIM:

To write a Python program to calculate the electricity bill based on the


slab given below:
Units Amt (per unit)
<=50 0
51-100 0.60
101-200 0.75
201-300 0.90
>300 1.15

SOURCE CODE:

units=int(input("Enter the units consumed: "))


if(units<=50):
amt=0.0
elif(units>=51 and units <=100):
amt=units*0.60
elif(units>=101 and units<=200):
amt=units*0.75
elif(units>=201 and units<=300):
amt=units*0.90
else:
amt=units*1.15
print("For the ",units," units, U have to pay:",amt)

INPUT/OUTPUT:

Enter the units consumed: 50


For the 50 units, U have to pay: 0.0

Enter the units consumed: 170


For the 170 units, U have to pay: 127.5

RESULT:
Thus the program is executed successfully.
Page 3 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO:4 AREA OF DIFFERENT SHAPES

DATE:

AIM:

To write a Python program to find the area of different shapes such as


square, rectangle, triangle and circle.

SOURCE CODE:

ch=0
while(ch!=5):
print("1. Square \n2. Rectangle \n3. Triangle \n4. Circle \n5. Exit")
ch=int(input("Enter Ur Choice"))

if(ch==1):
s=int(input("Enter the value of side:"))
a=s*s
print("Area of the Square:",a)

elif(ch==2):
l=int(input("Enter the value of length:"))
b=int(input("Enter the value of breadth:"))
a=l*b
print("Area of the Rectangle:",a)

elif(ch==3):
b=int(input("Enter the value of base:"))
h=int(input("Enter the value of height:"))
a=1/2*b*h
print("Area of the Triangle:",a)

elif(ch==4):
r=float(input("Enter the value of radius:"))
a=3.14*r*r
print("Area of the Circle:",a)

elif(ch==5):
print("Thank You !!!!")

else:
print("Enter the valid choice !!!!!")

Page 4 of 56
SSM SCHOOL PROGRAM MANUAL

INPUT/OUTPUT:

1. Square
2. Rectangle
3. Triangle
4. Circle
5. Exit

Enter Ur Choice1
Enter the value of side:5
Area of the Square: 25

Enter Ur Choice2
Enter the value of length:3
Enter the value of breadth:6
Area of the Rectangle: 18

Enter Ur Choice3
Enter the value of base:4
Enter the value of height:5
Area of the Triangle: 10.0

Enter Ur Choice4
Enter the value of radius:100
Area of the Circle: 31400.0

Enter Ur Choice5
Thank You!!!!

RESULT:

Thus the program is executed successfully.


Page 5 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO:5 SUM OF THE SERIES

DATE:

AIM:

To write a Python program to find the sum of the following series:

s=x/1!+x/2!+x/3!+ ……..+x/n!

SOURCE CODE:

x=int(input("Enter the value of X: "))


n=int(input("Enter the value for N: "))
s=0.0
for i in range(1,n+1):
f=1
for j in range(1,i+1):
f*=j
s+=x/f
print("Sum of the series: ",s)

INPUT/OUTPUT:

Enter the value of X: 2


Enter the value for N: 5
Sum of the series: 3.43

RESULT:

Thus the program is executed successfully.


Page 6 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 6 PRIME NUMBERS BETWEEN 1 AND N

DATE:

AIM:

To write a Python program to display the prime numbers between 1 and N.

SOURCE CODE:

n=int(input("Enter the value for n: "))


print("The Prime numbers between 1 and", n, "are")
for i in range(2,n+1):
flag=0
for j in range(2,i//2+1):
if (i % j==0):
flag=1
break
if(flag==0):
print(i, end=" ")

INPUT/OUTPUT:

Enter the value for n: 50

The Prime numbers between 1 and 50 are

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

RESULT:

Thus the program is executed successfully.

Page 7 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 7 CHECK THE NUMBER TYPE

DATE:
AIM:

To write a python program to check whether the given number is a


Perfect number, Armstrong number, and a Palindrome number.

SOURCE CODE:

n=int(input("Enter the number:"))


#Perfect number or not
sum =0
for i in range(1,n):
if n%i==0:
sum+=i
if sum==n:
print(n,"is a Perfect number")
else:
print(n,"is not a Perfect number")

#Armstrong number or not


temp=n
sum=0
while temp>0:
d=temp%10
temp=temp//10
sum+=d**3
if sum==n:
print(n,"is a an Armstrong number")
else:
print(n,"is not an Armstrong number")

#Palindrome number or not


rev=0
t=n
while t>0:
d=t%10
t=t//10
rev=rev*10+d
if n==rev:
print(n,"is a Palindrome number")
else:
print(n,"is not a Palindrome number")

Page 8 of 56
SSM SCHOOL PROGRAM MANUAL

INPUT/OUTPUT:

Enter the number:1331

1331 is not a Perfect number


1331 is not an Armstrong number
1331 is a Palindrome number

RESULT:

Thus the program is executed successfully

Page 9 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 8 TRIANGLE PATTERN - I

DATE:

AIM:

To write a Python program to generate the various triangle pattern using


nested for loop.

SOURCE CODE:

ch=0
while(ch!=6):
print("\n1.Horizontal \n2.Vertical \n3.Continous
\n4.Alpha(Left Align) \n5.Aplha(Right Align) \n6.Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
n=int(input("Enter the no of Steps: "))
for i in range(1,n+1):
for j in range(1,i+1):
print(i, end=" ")
print()

elif(ch==2):
n=int(input("Enter the no of Steps: "))
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end=" ")
print()

elif(ch==3):
k=1
n=int(input("Enter the no of Steps: "))
for i in range(1,n+1):
for j in range(1,i+1):
print(k, end=" ")
k=k+1
print()

elif(ch==4):
n=int(input("Enter the no of Steps(Left Align): "))
for i in range(n):
c=65
Page 10 of 56
SSM SCHOOL PROGRAM MANUAL

for j in range(i+1):
print(chr(c),end="")
c=c+1
print()

elif(ch==5):
n=int(input("Enter the no of Steps(Right Align): "))
for i in range(n):
c=65
for k in range(i,n-1):
print(end=" ")
for j in range(i+1):
print(chr(c),end="")
c=c+1
print()
elif(ch==6):
print("Thank You !!!")
else:
print("Enter the valid choice between 1 and 6")

INPUT/OUTPUT:

1.Horizontal
2.Vertical
3.Continous
4.Alpha(Left Align)
5.Aplha(Right Align)
6.Exit
Enter Ur Choice: 1
Enter the no of Steps: 5
1
22
333
4444
55555

Enter Ur Choice: 2
Enter the no of Steps: 5
1
12
123
1234
12345

Page 11 of 56
SSM SCHOOL PROGRAM MANUAL

Enter Ur Choice: 3
Enter the no of Steps: 5
1
23
456
7 8 9 10
11 12 13 14 15

Enter Ur Choice: 4
Enter the no of Steps(Left Align): 5
A
AB
ABC
ABCD
ABCDE

Enter Ur Choice: 5
Enter the no of Steps(Right Align): 5
A
AB
ABC
ABCD
ABCDE

Enter Ur Choice: 6
ThankYou!!!

RESULT:

Thus the program is executed successfully.


Page 12 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 9 TRIANGLE PATTERN - II

DATE:

AIM:

To write a Python program to generate the various triangle pattern using


nested for loop.

SOURCE CODE:

ch=0
while(ch!=6):
print("\n1.Pyramid \n2.Inverted Pyramid \n3.Hollow Pyramid
\n4.Inverted Hollow Pyramid \n5.Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
n=int(input("Enter the no of Steps: "))
for i in range(1,n+1):
for k in range(i,n):
print(end=" ")
for j in range(2*i-1):
print("*",end="")
print()

elif(ch==2):
n=int(input("Enter the no of Steps: "))
for i in range(n,-1,-1):
for k in range(i,n):
print(end=" ")
for j in range(2*i-1):
print("*",end="")
print()

elif(ch==3):
n=int(input("Enter the no of Steps: "))
for i in range(1,n+1):
for k in range(i,n):
print(end=" ")
for j in range(2*i-1):
if(j==0 or j==2*i-2 or i==n):
print("*",end="")
Page 13 of 56
SSM SCHOOL PROGRAM MANUAL

else:
print(end=" ")
print()

elif(ch==4):
n=int(input("Enter the no of Steps: "))
for i in range(n,-1,-1):
for k in range(i,n):
print(end=" ")
for j in range(2*i-1):
if(j==0 or j==2*i-2 or i==n):
print("*",end="")
else:
print(end=" ")
print()

elif(ch==5):
print("Thank You !!!")

else:
print("Enter the valid choice between 1 and 6")

INPUT/OUTPUT:

1.Pyramid
2.Inverted Pyramid
3.Hollow Pyramid
4.Inverted Hollow Pyramid
5.Exit
Enter Ur Choice: 1
Enter the no of Steps: 5
*
***
*****
*******
*********

Enter Ur Choice: 2
Enter the no of Steps: 5
*********
*******
*****
***
*
Page 14 of 56
SSM SCHOOL PROGRAM MANUAL

Enter Ur Choice: 3
Enter the no of Steps: 5
*
* *
* *
* *
*********

1.Pyramid
2.Inverted Pyramid
3.Hollow Pyramid
4.Inverted Hollow Pyramid
5.Exit
Enter Ur Choice: 4
Enter the no of Steps: 5

*********
* *
* *
**
*

Enter Ur Choice: 5
Thank You!!!

RESULT:

Thus the program is executed successfully.

Page 15 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 10 STRING MANIPULATIONS - I

DATE:

AIM:

To write a Python program toperform the string manipulation such as


length of string, copying a string, concatenation of strings, reversing a string
and comparing a string.

SOURCE CODE:

s3=""
s4=""
ch=0
while(ch!=6):
print("\n1.Length \n2.Copy \n3.Concat \n4.Reverse
\n5.Compare\n6.Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
s1=input("Enter String1: ")
length=0
for i in s1:
length+=1
print("\n Length of the String: ",length)

elif(ch==2):
s1=input("Enter String1: ")
for i in s1:
s3+=i
print("String Copied into S3 from S1:",s3)

elif(ch==3):
s1=input("Enter String1: ")
s2=input("Enter String2: ")
for i in s2:
s1+=i
print("String Concat of S1 and S2 in s1:",S1)

elif(ch==4):
s1=input("Enter String1: ")
length=0
Page 16 of 56
SSM SCHOOL PROGRAM MANUAL

for i in s1:
length+=1
for i in range(length-1,-1,-1):
s4+=s1[i]
print("Reversed String in S4: ",s4)

elif(ch==5):
flag=0
s1=input("Enter String1: ")
s2=input("Enter String2: ")
length1=0
for i in s1:
length1+=1
length2=0
for i in s2:
length2+=1
if(length1==length2):
for i in range(length1):
if(s1[i]!=s2[i]):
flag=1
break
if(flag==0):
print("Strings are Equal")
else:
print("Strings are not Equal")
else:
print("Strings are not Equal")
elif(ch==6):
print("Thank You :)")
else:
print("Enter a valid choice bw 1 and 6")

INPUT/OUTPUT:

1.Length
2.Copy
3.Concat
4.Reverse
5.Compare
6.Exit

Enter Ur Choice: 1
Enter String1: Chennai

Page 17 of 56
SSM SCHOOL PROGRAM MANUAL

Length of the String: 7

Enter Ur Choice: 2
Enter String1: Super Kings
String Copied into S3 from S1: Super Kings

Enter Ur Choice: 3
Enter String1: Chennai
Enter String2: Super Kings
String Concat of S1 and S2 in S1: ChennaiSuper Kings

Enter Ur Choice: 4
Enter String1: CSK
Reversed String in S4: KSC

Enter Ur Choice: 5
Enter String1: CSK
Enter String2: MI
Strings are not Equal

Enter Ur Choice: 6
Thank You :)

RESULT:
Thus the program is executed successfully.
Page 18 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 11 STRING MANIPULATIONS - II

DATE:

AIM:

To write a Python program to count the number of words, vowels, upper


case alphabets, digits and special character.

SOURCE CODE:

str1=input("Enter a Line: ")


w=1
v=0
d=0
u=0
s=0
vowel="aeiouAEIOU"

for i in range(len(str1)):
if(str1[i]>='0' and str1[i]<='9'):
d+=1
elif((str1[i]>='a' and str1[i]<='z') or (str1[i]>='A' and str1[i]<='Z')):
if(str1[i]>='A' and str1[i]<='Z'):
u+=1
if str1[i] in vowel:
v+=1
elif(str1[i]==' '):
w+=1
else:
s+=1

print("No of Words: ",w)


print("No of Vowels: ",v)
print("No of Upper Case: ",u)
print("No of Digits: ",d)
print("No of Spl Char: ",s)

INPUT/OUTPUT:

Page 19 of 56
SSM SCHOOL PROGRAM MANUAL

Enter a Line: ThIs is a NEW @ 12


No of Words: 6
No of Vowels: 4
No of Upper Case: 5
No of Digits: 2
No of Spl Char: 1

RESULT:

Thus the program is executed successfully.

Page 20 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 12 STRING MANIPULATION-III

DATE:
AIM:

To write a python program to count number of words, vowels, uppercase


alphabets, digits and special characters in a given string.

SOURCE CODE:

s=input("enter the string:")

print("""In a given string count:

1.Number of words\n2.Number of vowels\n3.Number of upper case


alphabets\n4.Number of digits 5.Number of special characters\n6.Exit""")

while True:

ch=int(input("enter your choice:"))

if ch==1:

count=0

for i in s:

if i==" ":

count+=1

print("Total number of words in the string is",count+1)

elif ch==2:

count=0

vowels="AEIOUaeiou"

for i in s:

if i in vowels:

count+=1

print("Total number of vowels in the string is",count)

elif ch==3:

count=0
Page 21 of 56
SSM SCHOOL PROGRAM MANUAL

for i in s:

if i>="A" and i<="Z":

count+=1

print("Total number of uppercase alphabets is", count)

elif ch==4:

count=0

for i in s:

if i>="0" and i<="9":

count+=1

print("Total number of digits in the string is",count)

elif ch==5:

count=0

c=0

for i in s:

if i>="A" and i<="Z" or i>="a" and i<="z" or i>="0" and i<="9":

c+=1

else:

count+=1

print("Total number of special characters in the string


is",count)

elif ch==6:

print("Thank you!")

else:

print("Invalid choice")

Page 22 of 56
SSM SCHOOL PROGRAM MANUAL

INPUT/OUTPUT:

enter the string: Today 27/05/2022 is the hottest day I have ever seen!!!

In a given string count:

1.Number of words

2.Number of vowels

3.Number of upper case alphabets

4.Number of digits

5.Number of special characters

6.Exit

enter your choice:1

Total number of words in the string is 10

enter your choice:2

Total number of vowels in the string is 14

enter your choice:3

Total number of uppercase alphabets is 2

enter your choice:4

Total number of digits in the string is 8

enter your choice:5

Total number of special characters in the string is 14

enter your choice:6

Thank you!

enter your choice:7

Invalid choice

RESULT:

Thus the program is executed successfully.

Page 23 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 13 LIST OPERATIONS- I


(INSERT AND DELETE AN ELEMENT IN A LIST)
DATE:

AIM:

To write a Python program to insert and delete an element in a list.

SOURCE CODE:

n= int(input("Input the number of values to be entered: "))


oned_list = [0 for size in range(n+2)]

print("User Inputs ")


for size in range(n):
x = int(input())
oned_list[size]= x
print()

print("User Entered Values: ",end=" ")


for size in range(n):
print(oned_list[size],end=" ")
print()

# Insert by Position
e=int(input("Enter an elem to be inserted: "))
x=int(input("Enter a position to insert the new ele: "))

for i in range(n):
if(x-1==i):
for j in range(n,i-1,-1):
oned_list[j]=oned_list[j-1]
oned_list[i]=e
n=n+1
break
print()
print("New Array after insertion: ",end="")
for size in range(n):
print(oned_list[size],end=" ")

Page 24 of 56
SSM SCHOOL PROGRAM MANUAL

# Delete by Element
x=int(input("\n Enter an elem to be deleted: "))

for i in range(n):
if(x==oned_list[i]):
print(oned_list[i]," deleted")
s=i
for j in range(s,n-1):
oned_list[j]=oned_list[j+1]
n=n-1
print()

print("After Deletion, Values are: ",end="")


for size in range(n):
print(oned_list[size],end=" ")

INPUT/OUTPUT:

Input the number of values to be entered: 5


User Inputs
2
3
1
7
9

User Entered Values: 2 3 1 7 9

Enter an elem to be inserted: 6


Enter a position to insert the new ele: 4
New Array after insertion: 2 3 1 6 7 9

Enter an elem to be deleted: 7


7 deleted
After Deletion, Values are: 2 3 1 6 9

RESULT:
Thus the program is executed successfully.
Page 25 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 14 LIST OPERATIONS- II


(MAXIMUM, MINIMUM AND SORTING)
DATE:

AIM:

To write a Python program to find the maximum & minimum element in


a list and also sort the list in ascending & descending order.

SOURCE CODE:

n=int(input("Enter the value of n: "))


L=[]
for i in range(0,n):
x=int(input("Enter a value: "))
list.insert(L,i,x)
ch=0
while(ch!=5):
print("\n1.Max \n2.Min \n3.Sort Asc \n4.Sort Desc \n5.Exit")
ch=int(input("Enter ur choice: "))

if(ch==1):
maxi=L[0]
for i in range(1,n):
if(maxi<L[i]):
maxi=L[i]
print("Max in the list: ",maxi)

elif(ch==2):
mini=L[0]
for i in range(1,n):
if(mini>L[i]):
mini=L[i]
print("Min in the list: ",mini)

elif(ch==3):
for i in range(0,n):
for j in range(i+1,n):
if(L[i]>L[j]):
t=L[i]
L[i]=L[j]
L[j]=t
print("Sorted List - Ascending")
Page 26 of 56
SSM SCHOOL PROGRAM MANUAL

for i in range(0,n):
print (L[i],end=" ")

elif(ch==4):
for i in range(0,n):
for j in range(i+1,n):
if(L[i]<L[j]):
t=L[i]
L[i]=L[j]
L[j]=t
print("Sorted List - Descending")
for i in range(0,n):
print (L[i],end=" ")

elif(ch==5):
print("Thank You")
exit()

else:
print("Enter a valid choice bw 1 and 5”)

INPUT/OUTPUT:

Enter the value of n: 5


Enter a value: 2
Enter a value: 6
Enter a value: 1
Enter a value: 8
Enter a value: 4

1.Max
2.Min
3.Sort Asc
4.Sort Desc
5.Exit

Enter ur choice: 1
Max in the list: 8

Enter ur choice: 2
Min in the list: 1

Enter ur choice: 3
Page 27 of 56
SSM SCHOOL PROGRAM MANUAL

Sorted List - Ascending


12468

Enter ur choice: 4
Sorted List - Descending
86421

Enter ur choice: 5
Thank You

RESULT:
Thus the program is executed successfully.

Page 28 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 15 LIST OPERATIONS - III


(MATRIX ADDITION AND MULTIPLICATION)
DATE:

AIM:

To write a Python program to perform the Matrix Addition and Matrix


Multiplication using nested list.

SOURCE CODE:

print("Enter the no of rows and columns for Mat A ")


r1 = int(input("Input number of rows: "))
c1= int(input("Input number of columns: "))
A = [[0 for col in range(c1)] for row in range(r1)]

print("Enter the Values for Mat A: ")


for i in range(r1):
for j in range(c1):
x = int(input("Enter a number: "))
A[i][j]= x

print("Enter the no of rows and columns for Mat B ")


r2 = int(input("Input number of rows: "))
c2= int(input("Input number of columns: "))
B = [[0 for col in range(c2)] for row in range(r2)]

print("Enter the Values for Mat B: ")


for i in range(r2):
for j in range(c2):
x = int(input("Enter a number: "))
B[i][j]= x

# Matrix Addition

if(r1==r2 and c1==c2):


print("Sum of Mat A and Mat B")
for i in range(r1):
for j in range(c2):
print(A[i][j]+B[i][j],end=" ")
print("")
else:

Page 29 of 56
SSM SCHOOL PROGRAM MANUAL

print("Mat Addition not possible between A and B")

# Matrix Multiplication

if(c1==r2):
print("Multiplication of Mat A and Mat B")
for i in range(r1):
for j in range(c2):
p=0
for k in range(r2):
p+=A[i][k]*B[k][j]
print(p,end=" ")
print("")
else:
print("Mat Multiplication not possible between A and B")

INPUT/OUTPUT:

Enter the no of rows and columns for Mat A


Input number of rows: 3
Input number of columns: 3

Enter the Values for Mat A:


Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9

Enter the no of rows and columns for Mat B


Input number of rows: 3
Input number of columns: 3

Page 30 of 56
SSM SCHOOL PROGRAM MANUAL

Enter the Values for Mat B:


Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9

Sum of Mat A and Mat B


246
8 10 12
14 16 18

Multiplication of Mat A and Mat B


30 36 42
66 81 96
102 126 150

RESULT:
Thus the program is executed successfully.

Page 31 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 16 LIST OPERATIONS - IV


(DISPLAYING MATRIX IN DIFFERENT FORMATS)
DATE:

AIM:

To write a Python program to display the Matrix in different formats such


as diagonal elements, Upper half Elements and Sum of Column Elements.

SOURCE CODE:

row_num = int(input("Input number of rows: "))


col_num = int(input("Input number of columns: "))
multi_list = [[0 for col in range(col_num)] for row in
range(row_num)]

for i in range(row_num):
for j in range(col_num):
print("a[",i,"][",j,"]: ",end="")
x = int(input())
multi_list[i][j]= x

print("\nThe Given Matrix")


for i in range(row_num):
for j in range(col_num):
print(multi_list[i][j],end=" ")
print("")

print("\n Diagonal Elements")


for row in range(row_num):
for col in range(col_num):
if(row==col or row+col==row_num-1):
print(multi_list[row][col],end=" ")
else:
print(end=" ")
print("")

print("\nUpper half Elements")


for row in range(row_num):
for col in range(col_num):
if(row<=col):
Page 32 of 56
SSM SCHOOL PROGRAM MANUAL

print(multi_list[row][col],end=" ")
else:
print(end=" ")
print("")

print("\nSum of Column Elements:")


for i in range(row_num):
for j in range(col_num):
print(multi_list[i][j],end="\t")
print("")
cols=[0 for col in range(col_num)]

for i in range(col_num):
for j in range(row_num):
cols[i]+=multi_list[j][i]

print("-------------------------")
for i in range(col_num):
print(cols[i],end="\t")
print()
print("-------------------------")

INPUT/OUTPUT:

Input number of rows: 3


Input number of columns: 3
a[ 0 ][ 0 ]: 1
a[ 0 ][ 1 ]: 2
a[ 0 ][ 2 ]: 3
a[ 1 ][ 0 ]: 4
a[ 1 ][ 1 ]: 5
a[ 1 ][ 2 ]: 6
a[ 2 ][ 0 ]: 7
a[ 2 ][ 1 ]: 8
a[ 2 ][ 2 ]: 9

The Given Matrix


123
456
Page 33 of 56
SSM SCHOOL PROGRAM MANUAL

789
Diagonal Elements
13
5
79

Upper half Elements


123
56
9

Sum of Column Elements:


12 3
45 6
78 9
-----------------------
12 15 18
-----------------------

RESULT:
Thus the program is executed successfully.

Page 34 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 17 TUPLE OPERATIONS- I


DATE:

AIM:

To write a Python program to perform the various tuple operations such


as length, slicing, concatenation, membership operator and count.

SOURCE CODE:

tup1=eval(input("Enter few overs score: "))


ch=0
while(ch!=6):
print("\n \t\t Tuple Operations ")
print(" 1.Length(To find no.of overs) \n 2.Slicing(To see specifc overs)")
print(" 3.Concatenation(Adding few overs) \n 4.Membership
Operator(Checking the score card) \n 5.Count \n 6.Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
print("No.of Overs: ",len(tup1))

elif(ch==2):
print("Enter the Starting and the Ending over:")
s, e =int(input()), int(input())
print("Slicing of Score Card: ")
print(tup1[s-1:e])

elif(ch==3):
tup2=eval(input("Enter few more overs score: "))
tup1=tup1+tup2
print("New Score Card: ",tup1)

elif(ch==4):
print("\t IN Operator")
print("Runs in the Scorecard: ",tup1)
x=int(input("Enter the runs to be searched: "))
if x in tup1:
print("Runs Present in the Over: ",tup1.index(x)+1)
else:
print("Runs Not Present in the Scorecard!!")

Page 35 of 56
SSM SCHOOL PROGRAM MANUAL

print("\t NOT IN Operator")


print("Runs in the Scorecard: ",tup1)
x=int(input("Enter the runs to be searched: "))
if x not in tup1:
print("Runs Not Present in the Scorecard")
else:
print("Runs Present in the Over: ",tup1.index(x)+1)

elif(ch==5):
print("Elements in tup1: ",tup1)
x=int(input("Enter the runs: "))
print(x,"runs present in the score card",tup1.count(x),"time(s)")

elif(ch==6):
print("Thank You!!")

else:
print("Enter the Valid Choice!!!")

INPUT/OUTPUT:

Enter few overs score: (2,4,5,2,7)

Tuple Operations

1.Length(To find no.of overs)

2.Slicing(To see specifc overs)

3.Concatenation(Adding few overs)

4.Membership Operator(Checking the score card)

5.Count

6.Exit

Enter Ur Choice: 1

No.of Overs: 5

Enter Ur Choice: 2

Enter the Starting and the Ending over:

24
Page 36 of 56
SSM SCHOOL PROGRAM MANUAL

Slicing of Score Card:

(4, 5, 2)

Enter Ur Choice: 3

Enter few more overs score: (2,8)

New Score Card: (2, 4, 5, 2, 7, 2, 8)

Enter Ur Choice: 4

IN Operator

Runs in the Scorecard: (2, 4, 5, 2, 7, 2, 8)

Enter the runs to be searched: 7

Runs Present in the Over: 5

NOT IN Operator

Runs in the Scorecard: (2, 4, 5, 2, 7, 2, 8)

Enter the runs to be searched: 2

Runs Present in the Over: 1

Enter Ur Choice: 5

Elements in tup1: (2, 4, 5, 2, 7, 2, 8)

Enter the runs: 2

2 runs present in the score card 3 time(s)

Enter Ur Choice: 6

Thank You!!

RESULT:
Thus the program is executed successfully.

Page 37 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 18 TUPLE OPERATIONS – II


DATE:

PROBLEM STATEMENT:
Write a Python program to perform Tuple operations such as finding the
minimum, maximum and sum of the elements of the tuple and sorting the
Tuple by converting it into a list.

AIM:

To write a Python program to perform Tuple operations such as finding


the minimum, maximum and sum of the elements of the tuple and sorting the
Tuple by converting it into a list.

SOURCE CODE:
ch=0
t = eval(input("Enter values for a tuple:"))
print("The tuple is :",t)
max_val = 0
min_val = t[0]

while ch!=5:
print("\n1. Maximum Value \n2. Minimum Value \n3. Sum of the
Values \n4. Sorting the values in tuple \n5. Exit")
ch=int(input("Enter you choice:"))
if ch==1:
for i in range(len(t)):
if max_val< t[i]:
max_val = t[i]
print("Maximum =",max_val)
elifch==2:
for i in range(1,len(t)):
if min_val> t[i]:
min_val = t[i]
print("Minimum =",min_val)
Page 38 of 56
SSM SCHOOL PROGRAM MANUAL

elifch==3:
s=0
for i in range(len(t)):
s+=t[i]
print("Sum of the values:",s)
elifch==4:
l=list(t)
l.sort()
print('Tuple Before Sorting: ',t)
t=tuple(l)
print("Tuple After Sorting:",t)
elifch==5:
print("Thank you!!!")
break
else:
print('Enter the option between 1 and 5')

INPUT/OUTPUT:
Enter values for a tuple:(23,43,12,64,33,76,47,88,55)
The tuple is : (23, 43, 12, 64, 33, 76, 47, 88, 55)

1. Maximum Value
2. Minimum Value
3. Sum of the Values
4. Sorting the values in tuple
5. Exit
Enter you choice:1
Maximum = 88

1. Maximum Value
2. Minimum Value
3. Sum of the Values
4. Sorting the values in tuple

Page 39 of 56
SSM SCHOOL PROGRAM MANUAL

5. Exit
Enter you choice:2
Minimum = 12

1. Maximum Value
2. Minimum Value
3. Sum of the Values
4. Sorting the values in tuple
5. Exit
Enter you choice:3
Sum of the values: 441

1. Maximum Value
2. Minimum Value
3. Sum of the Values
4. Sorting the values in tuple
5. Exit
Enter you choice:4
Tuple Before Sorting: (23, 43, 12, 64, 33, 76, 47, 88, 55)
Tuple After Sorting: (12, 23, 33, 43, 47, 55, 64, 76, 88)

1. Maximum Value
2. Minimum Value
3. Sum of the Values
4. Sorting the values in tuple
5. Exit
Enter you choice:5
Thank you!!!

RESULT:
Thus, the program is executed successfully.

Page 40 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 19 DICTIONARY OPERATIONS - I


(RETAIL PRODUCT CATALOG)
DATE:

AIM:

To write a Python program to perform the dictionary operation for Retail


Product Catalog to append, update, delete and display all the products.

SOURCE CODE:

prod=dict()
n=int(input("Enter the no.of products: "))

i=1
while i<=n:
pname=input("Enter the product name: ")
pri=float(input("Enter the Price: "))
prod[pname]=pri
i=i+1

ch=0
while ch!=5:
print("1.Append \n2.Update \n3.Delete \n4.Display all \n5.Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
pname=input("Enter the new product name: ")
pri=float(input("Enter the Price: "))
prod[pname]=pri
print("\n\t Product Appended Successfully!!!")

elif(ch==2):
upn=input("Enter the product name to be updated: ")
if upn in prod:
npr=float(input("Enter the New Price: "))
prod[pname]=npr
print("\n\t Product Price Updated Successfully!!!")
else:
print("Product doesn't Exist")

elif(ch==3):
upn=input("Enter the product name to be deleted: ")

Page 41 of 56
SSM SCHOOL PROGRAM MANUAL

if upn in prod:
print(upn,end=" ")
print(prod.pop(upn),end=" ")
print("\t Product Info Deleted !!!")
else:
print("Product doesn't Exist")

elif(ch==4):
print("\nProduct Name \t Price")
for i in prod:
print(i,"\t",prod[i])

elif(ch==5):
print("Thank You:)")

else:
print("Enter the choice bw 1 and 4")

INPUT/OUTPUT:

Enter the no. of products: 3

Enter the product name: Colgate

Enter the Price: 20.75

Enter the product name: Pepsodent

Enter the Price: 17.75

Enter the product name: Sensodyne

Enter the Price: 35

1.Append

2.Update

3.Delete

4.Display all

5.Exit

Page 42 of 56
SSM SCHOOL PROGRAM MANUAL

Enter Ur Choice: 1

Enter the new product name: Close Up

Enter the Price: 25.50

Product Appended Successfully!!!

Enter Ur Choice: 2

Enter the product name to be updated: Colgate

Enter the New Price: 22

Product Price Updated Successfully!!!

Enter Ur Choice: 4

Product Name Price

Colgate 20.75

Pepsodent 17.75

Sensodyne 35.0

Close Up 22.0

Enter Ur Choice: 3

Enter the product name to be deleted: Sensodyne

Sensodyne 35.0 Product Info Deleted!!!

Enter Ur Choice: 5

Thank You:)

RESULT:
Thus the program is executed successfully.
Page 43 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 20 DICTIONARY OPERATIONS - II


(LIBRARY MANAGEMENT SYSTEM)
DATE:

AIM:

To write a Python program to perform the dictionary operations for library


management system to add, search, pop, check total books and clear all books.

SOURCE CODE:

book=dict()
ch=0

while ch!=6:
print("\n\n\t\t ********* Library Management System *********")
print("1. Add new \n2. Search \n3. Pop \n4. Check Total books
\n5. Clear all \n6. Exit")
ch=int(input("Enter Ur Choice: "))

if(ch==1):
bid=int(input("Enter the ISBN: "))
n=input("Enter the book name: ")
p=float(input("Enter the price: "))
y=int(input("Enter the Publication Year: "))
book[bid]=(n,p,y)

elif(ch==2):
bk=int(input("Enter the ISBN for searching: "))
if bk in book:
print(" Name, Price, Year ")
print(book.get(bk))
else:
print("ISBN not available")
elif(ch==3):
bk=int(input("Enter the ISBN for deleting: "))
if bk in book:
del book[bk]
print("Record deleted !!!!")
else:
print("ISBN not available")

Page 44 of 56
SSM SCHOOL PROGRAM MANUAL

elif(ch==4):
for i in book:
print(i,end="\t")
t=book[i]
for j in t:
print(j,end="\t")
print()
print("\n Total books : ",len(book))

elif(ch==5):
book.clear()
print("All the records deleted !!!")

elif(ch==6):
print("\n \t Thank You!!! Visit Again!!")

else:
print("Enter the valid choice between 1 and 6")

INPUT/OUTPUT:

********* Library Management System *********


1. Add new
2. Search
3. Pop
4. Check Total books
5. Clear all
6. Exit

Enter Ur Choice: 1
Enter the ISBN: 1001
Enter the book name: Operating System
Enter the price: 350
Enter the Publication Year: 2009

Enter Ur Choice: 1
Enter the ISBN: 1002
Enter the book name: Data structure
Enter the price: 420
Enter the Publication Year: 2007

Page 45 of 56
SSM SCHOOL PROGRAM MANUAL

Enter Ur Choice: 1
Enter the ISBN: 1003
Enter the book name: System Analysis and Design
Enter the price: 520
Enter the Publication Year: 2008

Enter Ur Choice: 2
Enter the ISBN for searching: 1002
Name, Price, Year
('Data structure', 420.0, 2007)

Enter Ur Choice: 4
1001 Operating System 350.0 2009
1002 Data structure 420.0 2007
1003 System Analysis and Design 520.0 2008
Total books: 3

Enter Ur Choice: 3
Enter the ISBN for deleting: 1003
Record deleted!!!

Enter Ur Choice: 5
All the records deleted!!!

Enter Ur Choice: 6
Thank You!!! Visit Again!!

RESULT:
Thus the program is executed successfully.
Page 46 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 21 DICTIONARY OPERATIONS – III


DATE:

PROBLEM STATEMENT:
Write a program to create a dictionary whose keys are month names and
whose values are the number of days in the corresponding months and perform
the following functions.
1. Ask the user to enter a month name and use the dictionary to tell how
many days are in the month.
2. Print out all the months with 31 days
3. Print out all the keys in alphabetical order
4. Print out the (key-value) pair sorted by the number of days in each
month.
AIM:
To create a dictionary whose keys are month names and whose values
are the number of days in the corresponding months and perform the following
functions.
1. Ask the user to enter a month name and use the dictionary to tell how
many days are in the month.
2. Print out all the months with 31 days
3. Print out all the keys in alphabetical order
4. Print out the (key-value) pair sorted by the number of days in each
month.

SOURCE CODE:

months={'January':31,'February':28, 'March':31, 'April':30,'May':31,


'June':30,'July':31,'August':31,'September':30,'October':31,
'November':30,'December':31}
ch=0
while ch!=5:
print('''\n\t 1. Enter a month to know its days
2. Months with 31 days

Page 47 of 56
SSM SCHOOL PROGRAM MANUAL

3. Months(Names) in alphabetical order


4. Months and days sorted by number of days in each month
5. Exit''')
ch = int(input("Enter your choice:"))
if ch==1:
m=input("Enter a month(Eg: January)")
if m in months:
print("The number of days in",m,"is",months.get(m))
else:
print("Pls mention the month name as specified...")
elifch==2:
print("Months with 31 days:")
for i in months:
if months[i]==31:
print(i,end=" ")
elifch==3:
print("Months name sorted in alphabetical order:")
print(sorted(months))
elifch==4:
print("Months and days sorted by number of days in each month")
v=sorted([(i,j) for j, i in months.items()])
print([(j,i) for i, j in v])
else:
print("Thank you!!!")
break

INPUT/OUTPUT:
1. Enter a month to know its days
2. Months with 31 days
3. Months(Names) in alphabetical order
4. Months and days sorted by number of days in each month
5. Exit

Page 48 of 56
SSM SCHOOL PROGRAM MANUAL

Enter your choice:1


Enter a month(Eg: January)November
The number of days in November is 30

1. Enter a month to know its days


2. Months with 31 days
3. Months(Names) in alphabetical order
4. Months and days sorted by number of days in each month
5. Exit
Enter your choice:2
Months with 31 days:
January March May July August October December

1. Enter a month to know its days


2. Months with 31 days
3. Months(Names) in alphabetical order
4. Months and days sorted by number of days in each month
5. Exit
Enter your choice:3
Months name sorted in alphabetical order:
['April', 'August', 'December', 'February', 'January', 'July', 'June', 'March', 'May',
'November', 'October', 'September']

1. Enter a month to know its days


2. Months with 31 days
3. Months(Names) in alphabetical order
4. Months and days sorted by number of days in each month
5. Exit
Enter your choice:4
Months and days sorted by number of days in each month
[('February', 28), ('April', 30), ('June', 30), ('November', 30), ('September', 30),
('August', 31), ('December', 31), ('January', 31), ('July', 31), ('March', 31), ('May',
31), ('October', 31)]

Page 49 of 56
SSM SCHOOL PROGRAM MANUAL

1. Enter a month to know its days


2. Months with 31 days
3. Months(Names) in alphabetical order
4. Months and days sorted by number of days in each month
5. Exit
Enter your choice:5
Thank you!!!

RESULT:
Thus, the program is executed successfully.

Page 50 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 22 PYTHON MODULES


DATE:

PROBLEM STATEMENT:
Write a program to import math, random and statistics modules and use
the following built-in functions.
(i) math – pow, floor, gcd
(ii) random – random, randint, randrange
(iii) statistics – mean, median, mode

AIM:
To write a program to import math, random and statistics modules and
use the following built-in functions.
(i) math – pow, floor, gcd
(ii) random – random, randint, randrange
(iii) statistics – mean, median, mode

SOURCE CODE:
import math
import random
import statistics as s

while True:
print("\n1. math module \n2. random module \n3. statistics module \n4.
Exit")
ch=int(input("\nSelect a module"))

#math module
if ch==1:
#pow
print("To calculate power")
a=int(input("Enter the base:"))
b=int(input("Enter the power:"))

Page 51 of 56
SSM SCHOOL PROGRAM MANUAL

ans=math.pow(a,b)
print("The power value is =",ans)

#floor
print("To find the floor value of a number")
f=float(input("Enter a decimal number:"))
ans=math.floor(f)
print("The floor value is =",ans)

#gcd
print("To find GCD of two numbers")
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
gcd=math.gcd(a,b)
print("The gcd value is =",gcd)

#random module
if ch==2:
print("First random number :",random.random())
print("Second random number :",random.random())
print("Random integer between 1 to 12: ",random.randint(1,12))
print("Random number using randrange:",random.randrange(100,200))

#statistics module
if ch==3:
f=eval(input("Enter the list of values separated by comma:"))
m=s.mean(f)
print("The mean value is :",m)
med=s.median(f)
print("The median value is: ",med)
mod=s.mode(f)
print("The mode value is :",mod)

Page 52 of 56
SSM SCHOOL PROGRAM MANUAL

if ch==4:
print("Thank You!!!")
break

INPUT/OUTPUT:
1. math module
2. random module
3. statistics module
4. Exit

Select a module1
To calculate power
Enter the base:4
Enter the power:2
The power value is = 16.0
To find the floor value of a number
Enter a decimal number:32.8
The floor value is = 32
To find GCD of two numbers
Enter the first number:45
Enter the second number:81
The gcd value is = 9

1. math module
2. random module
3. statistics module
4. Exit

Select a module2
First random number : 0.551475377536751
Second random number : 0.9071331295429417
Random integer between 1 to 12: 2
Random number using randrange: 149

Page 53 of 56
SSM SCHOOL PROGRAM MANUAL

1. math module
2. random module
3. statistics module
4. Exit

Select a module3
Enter the list of values separated by
comma:23,48,45,21,16,38,64,21,45,78,55,45
The mean value is : 41.583333333333336
The median value is: 45.0
The mode value is : 45

1. math module
2. random module
3. statistics module
4. Exit

Select a module4
Thank You!!!

RESULT:
Thus, the program is executed successfully.

Page 54 of 56
SSM SCHOOL PROGRAM MANUAL

PGM.NO: 23 NUMBER CONVERSIONS

DATE:

AIM:

To write a Python program to convert the given decimal number to its


equivalent binary, octal and hexadecimal numbers.

SOURCE CODE:

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


d=n
binary = [0 for size in range(10)]
i=0
while(d>0):
binary[i]=int(d%2)
d=int(d/2)
i=i+1

i=i-1
print("Binary Equivalent: ",end=" ")
while(i>=0):
print(binary[i],end="")
i=i-1
print()

o=n
octal = [0 for size in range(10)]
i=0
while(o>0):
octal[i]=int(o%8)
o=int(o/8)
i=i+1
i=i-1
print("Octal Equivalent: ",end=" ")
while(i>=0):
print(octal[i],end="")
i=i-1
print()

h=n

Page 55 of 56
SSM SCHOOL PROGRAM MANUAL

hexa = [0 for size in range(10)]


i=0
while(h>0):
hexa[i]=int(h%16)
h=int(h/16)
i=i+1

i=i-1
print("Hexadecimal Equivalent: ",end=" ")
while(i>=0):
if(hexa[i]==10):
print('A',end="")
elif(hexa[i]==11):
print('B',end="")
elif(hexa[i]==12):
print('C',end="")
elif(hexa[i]==13):
print('D',end="")
elif(hexa[i]==14):
print('E',end="")
elif(hexa[i]==15):
print('F',end="")
else:
print(hexa[i],end="")
i=i-1

INPUT/OUTPUT:

Enter a number: 255


Binary Equivalent: 11111111
Octal Equivalent: 377
Hexadecimal Equivalent: FF

RESULT:

Thus the program is executed successfully.

Page 56 of 56

You might also like