[go: up one dir, main page]

0% found this document useful (0 votes)
27 views21 pages

PYTHON

The document is a certificate for a student who completed a Python programming lab at Jamal Mohamed College. It lists the student's name, register number, and roll number. It also contains a table with 13 programming tasks completed by the student, including tasks demonstrating data types, calculating distance, finding factorials, and more. The certificate is signed by the staff in charge and submitted for examination.

Uploaded by

tharanben
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)
27 views21 pages

PYTHON

The document is a certificate for a student who completed a Python programming lab at Jamal Mohamed College. It lists the student's name, register number, and roll number. It also contains a table with 13 programming tasks completed by the student, including tasks demonstrating data types, calculating distance, finding factorials, and more. The certificate is signed by the staff in charge and submitted for examination.

Uploaded by

tharanben
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/ 21

JAMAL MOHAMED COLLEGE (AUTONOMOUS)

College with Potential for Excellence


Accredited (4 Cycle) with ‘A++’ Grade with CGPA 3.69 out of 4 by NAAC
th

(Affiliated to Bharathidasan University)


TIRUCHIRAPPALLI – 620 020

DEPARTMENT OF COMPUTER APPLICATIONS [MEN]

BACHELOR OF COMPUTER APPLICATIONS

SEMESTER – 5

PYTHON PROGRAMMING LAB(20UCA5CC12P2)

CERTIFICATE

Name : _______________________ Class __________________

Register Number : Roll Number :

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 :

Internal Examiner External Examiner


S.NO DATE TITLE OF THE PROGRAM PAGE NO
1. DEMONSTRATE DIFFERENT
NUMBER DATA TYPES
2. CALCULATE EUCLIDEAN
DISTANCE BETWEEN TWO POINTS
BY TAKING INPUT FROM THE
USER
3. FIND THE FACTORIAL OF A
GIVEN NUMBER USING FUNCTION
4. PRINT WHETHER A NUMBER
POSITIVE OR NEGATIVE USING
IF-ELSE
5. CREATE A SIMPLE CALCULATOR
USING IF-ELIF STATEMENT
6. FIND THE SUM OF ALL PRIME
NUMBERS BETWEEN 1 TO 100
USING FOR LOOP
7. COMPUTE THE NUMBER OF
CHARACTERS, WORDS AND LINES
IN A FILE
8. PRINT ALL OF THE UNIQUE
WORDS IN THE FILE IN
ALPHABETICAL ORDER
9. DEFINE A MODULE TO FIND
FIBONACCI NUMBERS AND
IMPORT THE MODULE TO
ANOTHER PROGRAM
10. CREAT A LIST AND PERFORM
THE FOLLOWING OPERATIONS
(a)insert() (b)remove()
(c)append() (d)len()
(e)pop()
11. CREATE A TUPLE AND PERFORM
THE FOLLOWING OPERATIONS
(a)Concatenation
(b)Repetition
(c)Membership
(d)Access items
(e)Slicing

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:

#START THE PROGRAM


print("Data Type Identifier")

#PROMPT THE USER FOR INPUT


user_input = input("Enter Some Data")

#DETERMINE THE DATA TYPE OF THE INPUT


data_type = type(user_input)

#DISPLAY THE RESULT OF THE USER


print("The data type of the user input is ",data_type)

OUTPUT:

Data Type Identifier


Enter Some Data ashar
The data type of the user input is <class 'str'>
2. CALCULATE EUCLIDEAN DISTANCE BETWEEN TWO
POINTS BY TAKING INPUT FROM THE USER

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

Euclidean Distance is : 14.142135623730951


3. FIND THE FACTORIAL OF A GIVEN NUMBER USING
FUNCTION

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:

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


if (num == 0):
print(num," is neither Positive nor Negative")
else:
if (num > 0):
print(num," is Positive")
else:
print(num," is Negative")

OUTPUT:

Enter a Number: 6
6 is Positive
5. CREATE A SIMPLE CALCULATOR USING IF-ELIF
STATEMENT.

PROGRAM:

#SIMPLE CALCULATOR PROGRAM

a = int(input("Enter a value of a : "))


b = int(input("Enter a value of b : "))

cho = int(input("Enter your Choise as \n1.Addition


\n2.Subraction \n3.Multiplication \n4.Division \n5.Modulo
Division"))

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

print("Sum of all Prime Numbers are ",sum)


print("Count of all Prime Numbers are ",count)

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

print("\n Given File ")


print(s)

print("\n Characters in a given file = ",len(s))


m = s.split()
print("\n Words in a given file = ",len(m))

l = 0

for x in s:
if x == "\n" or x == "\r":
l = l + 1
print("\n Lines in a given file = ",l)

INPUT:

File Name : “sam.txt”

prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken

OUTPUT:

Given File
prasanna srinivasan
sivabalan
sriram dinesh
abinash
gowtham dot broken

Characters in a given file = 70

Words in a given file = 9

Lines in a given file = 4


8. PRINT ALL OF THE UNIQUE WORDS IN THE FILE IN
ALPHABETICAL ORDER

PROGRAM:

t = open("sam.txt","r")
s = t.read()

print("\n Given File ")


print(s)

s = s.split()
s.sort()

print("\n File contents in Alphabetical Order")

for x in s:
print(x)

INPUT:

File Name : “sam.txt”

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)

#To implement insert() method


name.insert(3,'sam')
print("\n Values in the list after insertion ",name)

#To implement remove() method


name.remove('deepak')
print("\n Values in the list after remove operation ",name)

#To implement append() method


name.append('Tamil')
print("\n Values in the list after append operation ",name)

#To implement len() method


print("\n Length of the list name are ",len(name))

#To implement pop() method


name.pop()
print("\n Values in the list after pop operation ",name)

name.pop(3)
print("\n Values in the list after pop(3) operation ",name)

OUTPUT:

Values in the list are


['prasanna', 'santhosh', 'nowfal', 'deepak', 'abinash']

Values in the list after insertion


['prasanna', 'santhosh', 'nowfal', 'sam', 'deepak',
'abinash']

Values in the list after remove operation


['prasanna', 'santhosh', 'nowfal', 'sam', 'abinash']

Values in the list after append operation


['prasanna', 'santhosh', 'nowfal', 'sam', 'abinash',
'Tamil']

Length of the list name are 6

Values in the list after pop operation


['prasanna', 'santhosh', 'nowfal', 'sam', 'abinash']

Values in the list after pop(3) operation


['prasanna', 'santhosh', 'nowfal', 'abinash']
11. CREATE A TUPLE AND PERFORM THE FOLLOWING
OPERATIONS
(a)Concatenation (b)Repetition (c)Membership (d)Access items
(e)Slicing

PROGRAM:

t1 = (10,20,30)
t2 = (40,50,60)

print("\n t1 Values ",t1)


print("\n t2 Values ",t2)

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

t1 Values (10, 20, 30)

t2 Values (40, 50, 60)

Concatenation Values (10, 20, 30, 40, 50, 60)

Tuple with repeated values of t1 three times (10, 20, 30,


10, 20, 30, 10, 20, 30)

Enter the value to check membership on t1 60


60 is not a member

3rd values in t1 = 30

0rh values in t1 = 10

Values from inder(1) to (4) (20, 30, 40, 50, 60)

Values from inder(1) to t1 20


12. SORT(ASCENDING AND DESCENDING) A DICTIONARY BY
VALUE

PROGRAM:

data = {
"21UCA262" : "Akash",
"21UCA266" : "Haider",
"21UCA306" : "Mohamed",
"21UCA291" : "Prasanna",
"21UCA291" : "Srinivasan"}

m = list(data.values())
print("\n Data values ",m)

#To ascending the order


m.sort()
print("\n Data in Ascending order ",m)

#To descending the order


m.reverse()
print("\n Data in Descending order ",m)

OUTPUT:

Data values ['Akash', 'Haider', 'Mohamed', 'Srinivasan']

Data in Ascending order ['Akash', 'Haider', 'Mohamed',


'Srinivasan']

Data in Descending order ['Srinivasan', 'Mohamed',


'Haider', 'Akash']
13. PREPARE A STUDENT MARK LIST USING CLASS

PROGRAM:

#DEFINE THE CLASS


class stud:
def init (self,rollno,m1,m2,m3):
#Initialixe object attributes
self.rollno = rollno
self.a1 = m1
self.a2 = m2
self.a3 = m3
self.tot = 0

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:

#DEFINE THE CLASS


class circle:
def area(self,r):
res = 3.14 * r * r
print("Area of Circle = ",res)
x = circle()
x.area(10)

OUTPUT:

Area of Circle = 314.0

You might also like