PYTHON
PYTHON
SEMESTER – 5
CERTIFICATE
This is to certify that this is the bonafide record of practical work done in the Computer
Centre of Jamal Mohamed College, Tiruchirappalli - 20 during the Year 2023 - 2024.
Staff in-charge
Submitted for the Bachelor of Computer Applications Practical Examination held at Jamal
Mohamed College, Tiruchirappalli - 20, on .
Tiruchirappalli - 20
Date :
12 SORT(ASCENDING AND
DESCENDING)A DICTIONARY BY
VALUE
13 PREPARE A STUDENT MARK LIST
USING CLASS
14 FIND THE AREA OF CIRCLE
USING CLASS AND OBJECT
1. DEMONSTRATE DIFFERENT NUMBER DATA TYPES
PROGRAM:
OUTPUT:
PROGRAM:
import math
x1 = int(input("Enter x1: "))
x2 = int(input("Enter x2: "))
y1 = int(input("Enter y1: "))
y2 = int(input("Enter y2: "))
a = x2 - x1
b = y2 - y1
s = a*a + b*b
print("\n s = ",s)
ed = math.sqrt(s)
print("\n Euclidean Distance is : ",ed)
OUTPUT:
Enter x1: 10
Enter x2: 20
Enter y1: 15
Enter y2: 25
s = 200
PROGRAM:
def factorial():
f = int(input("Enter a Number: "))
for i in range(1,f):
f = i * f
print(f)
factorial()
OUTPUT:
Enter a Number: 6
720
4. PRINT WHETHER A NUMBER POSITIVE OR NEGATIVE
USING IF-ELSE
PROGRAM:
OUTPUT:
Enter a Number: 6
6 is Positive
5. CREATE A SIMPLE CALCULATOR USING IF-ELIF
STATEMENT.
PROGRAM:
if cho == 1:
print("Addition of two number is ",a+b)
elif cho == 2:
print("Subraction of two number is ",a-b)
elif cho == 3:
print("Multiplication of two number is ",a*b)
elif cho == 4:
print("Division of two number is ",a//b)
elif cho == 5:
print("Modulo Division of two number is ",a%b)
else:
print("Your choise is wrong. ... ")
OUTPUT:
Enter a value of a : 10
Enter a value of b : 25
Enter your Choise as
1.Addition
2.Subraction
3.Multiplication
4.Division
5. Modulo Division 3
Multiplication of two number is 250
6. FIND THE SUM OF ALL PRIME NUMBERS BETWEEN 1 TO
100 USING FOR LOOP.
PROGRAM:
sum = 0
count = 0
for n in range(2,101):
p = 1
for i in range(2,n):
if (n % i) == 0:
p = 0
if p == 1:
print(n," is Prime")
sum += 0
count += 1
OUTPUT:
2 is Prime
3 is Prime
5 is Prime
7 is Prime
11 is Prime
13 is Prime
17 is Prime
19 is Prime
23 is Prime
29 is Prime
31 is Prime
37 is Prime
41 is Prime
43 is Prime
47 is Prime
53 is Prime
59 is Prime
61 is Prime
67 is Prime
71 is Prime
73 is Prime
79 is Prime
83 is Prime
89 is Prime
97 is Prime
Sum of all Prime Numbers are 0
Count of all Prime Numbers are 25
7. COMPUTE THE NUMBER OF CHARACTERS, WORDS AND
LINES IN A FILE
PROGRAM:
t = open("sam.txt","r")
s = t.read()
l = 0
for x in s:
if x == "\n" or x == "\r":
l = l + 1
print("\n Lines in a given file = ",l)
INPUT:
prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken
OUTPUT:
Given File
prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken
PROGRAM:
t = open("sam.txt","r")
s = t.read()
s = s.split()
s.sort()
for x in s:
print(x)
INPUT:
prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken
OUTPUT:
Given File
prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken
File contents in Alphabetical Order
abinash
broken
dinesh
dot
gowtham
prasanna
sivabalan
srinivasan
sriram
9. DEFINE A MODULE TO FIND FIBONACCI NUMBERS AND
IMPORT THE MODULE TO ANOTHER PROGRAM
PROGRAM:
pras.py
def fib(n):
f1,f2 = 0,1
while f1< n :
print(f1,end = " ")
f1,f2 = f2,f1+f2
print()
pras2.py
import pras
print("Displaying fib(100)")
pras.fib(100)
OUTPUT:
Displaying fib(100)
0 1 1 2 3 5 8 13 21 34 55 89
10. CREAT A LIST AND PERFORM THE FOLLOWING OPERATIONS
(a)insert() (b)remove() (c)append() (d)len() (e)pop()
PROGRAM:
name = ['prasanna','santhosh','nowfal','deepak','abinash']
print("\n Values in the list are ",name)
name.pop(3)
print("\n Values in the list after pop(3) operation ",name)
OUTPUT:
PROGRAM:
t1 = (10,20,30)
t2 = (40,50,60)
#Concatenation
t3 = t1 + t2
print("\n Concatenation Values ",t3)
#Repetition
r = t1 * 3
print("\n Tuple with repeated values of t1 three times ",r)
#Membership
x = int(input("\n Enter the value to check membership on
t1"))
if x in t1:
print(x,"is a member")
else:
print(x," is not a member")
#Access Items
print("\n 3rd values in t1 = ",t1[2])
print("\n 0rh values in t1 = ",t1[-3])
#Slicing
print("\n Values from inder(1) to (4) ",t3[1: ])
print("\n Values from inder(1) to t1 ",t1[1])
OUTPUT:
3rd values in t1 = 30
0rh values in t1 = 10
PROGRAM:
data = {
"21UCA262" : "Akash",
"21UCA266" : "Haider",
"21UCA306" : "Mohamed",
"21UCA291" : "Prasanna",
"21UCA291" : "Srinivasan"}
m = list(data.values())
print("\n Data values ",m)
OUTPUT:
PROGRAM:
def find_tot(self):
self.tot = self.a1 + self.a2 + self.a3
print("Total Marks = ",self.tot)
s1 = stud(1001,88,99,78)
print("Student roll is : ",s1.a1)
s1.find_tot()
OUTPUT:
Student roll is : 88
Total Marks = 265
14. FIND THE AREA OF CIRCLE USING CLASS AND OBJECT
PROGRAM:
OUTPUT: