0% found this document useful (0 votes)
5 views29 pages

Python Programming Lab Exercises

The document is a Python lab record for a student named Ponmani Asikha from Women's Christian College, detailing various programming exercises and algorithms. It includes programs for determining leap years, calculating factorials, generating Fibonacci series, and performing file operations, among others. Each section outlines the aim, algorithm, and code for the respective tasks, showcasing fundamental Python programming concepts.

Uploaded by

ponmaniasikha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views29 pages

Python Programming Lab Exercises

The document is a Python lab record for a student named Ponmani Asikha from Women's Christian College, detailing various programming exercises and algorithms. It includes programs for determining leap years, calculating factorials, generating Fibonacci series, and performing file operations, among others. Each section outlines the aim, algorithm, and code for the respective tasks, showcasing fundamental Python programming concepts.

Uploaded by

ponmaniasikha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

DEPARTMENT OF COMPUTER APPLICATIONS

(SELF FINANCED SECTION)

WOMEN'S CHRISTIAN COLLEGE

CHENNAI - 600 006.

(An Autonomous Institution-Affiliated to the University of Madras)

PYTHON LAB

Name : _Ponmani Asikha_________

Reg. No. : _25BCA036__________________


An Autonomous Institution-Affiliated to the University of Madras

This is to certify that this is the record work done by

_Ponmani Asikha.G__of _I-BCA department(1st semester)__during

_2025-2026
DEPARTMENT OF
COMPUTER APPLICATIONS
[Document subtitle]

[DATE]
Leap year:
AIM

To write a program to display whether the given year is a leap year or not
ALGORITHM:

Step1:start
Step2:read the value of a
Step3:if(a%4==0)
Display leap year else
Display not a leap year
Step4:stop

CODE:

a=int(input("enter the year"))


if(a%4==0):
print("leap0 year")
else:
print("not a leap year")
Days of the week:
AIM:

To write a program for finding the day of the week


ALGORITHM:

Step1:start
Step2:read the value of day
Step3:if day is equal to 1
Display Sunday
Else if day is equal to 2
Display Monday
Else if day is equal to 3
Display Tuesday
Else if day is equal to 4
Display Wednesday
Else if day is equal to 5
Display Thursday
Else if day is equal to 6
Display Friday
Else if day is equal to 7
Display Saturday
Else display error
Step4:stop
CODE:

day=int(input("enter a number:"))
if(day==1):
print("sunday")
elif(day==2):
print("monday")
elif(day==3):
print("tuesday")
elif(day==4):
print("wednesday")
elif(day==5):
print("thursday")
elif(day==6):
print("friday")
elif(day==7):
print("saturday")
else:
print("error")
Sum of series:
AIM:

To write a program to print the sum of series of the given number


ALGORITHM:

Step1:start
Step2:read the value of n
Step3:declare the variable
Total=0
Step4:repeat the steps until I in range(1,n+1)
Total=total+i
Step5:display the value of total
Step6:stop

Factorial:
AIM:
To write a program to print the factorial value of a given number
ALGORITHM:

Step1:start
Step2:read the value of n
Step3:declare the variable
step4:repeat the steps until I in range(1,n+1)
step5:display the value of total
step6:stop

Multiplication table:
AIM:

To write a program to print a multiplication table of the given number


ALGORITHM:
Step1:start
Step2:read the value of n
Step3:declare steps until i=1
Step4:repect steps until i<=10
Display the message(I,”X”,n,”=”,i*n)
Step5:increment i by 1
Step6:stop

Greatest of three numbers


AIM:

To write a program to display the greatest of the given number

ALGORITHM:

Step1:start
Step2:read the value of a,b,c
Step3:if a is the greater than b
And a is greater than c
Display a is the greatest number
Else b is greater than a
And b is greater than c
Display b is the grestest number
Step4:stop

Fibonacci series:
AIM:

To write a program to print the fibonacci series of a given number


ALGORITHM:

STEP1:START
Step2:declare the variable first=0 and second=1
Step3:print the value of first
Step4:print the value of second
Step5:declare the variable i=1
Step6:repeat the steps until (i<=n)
Third=first+second
Display(third)
First=second
Second=third
Step7:increment I by 1
Step8:stop

TO FIND A CHARACTER:
AIM:

To write a program to print whether a given character is in given string


ALGORITHM:

Step1:start
Step2:read the values of a
Step3:read the value of b
Step4:if(b in a)
Display character found
Or else display character not found
Step5:stop

Array search:
Aim:

To search for an element in an array.


Algorithm:

1. Start
2. Create an array with elements.
3. Read the element to be searched.
4. Compare the element with array elements.
5. If found, display “Element present”.
6. Else, display “Element not present”.
7. Stop

Program:
arr = [10, 20, 30, 40, 50]

x = 30
if x in arr:
print(f"{x} is present in the array")
else:
print(f"{x} is not in the array")

Output:

30 is present in the array

Your text here

Array multiplication:
Aim:

To multiply two arrays element-wise.


Algorithm:

8. Start
9. Create two arrays of equal size.
10. Multiply corresponding elements.
11. Store results in a third array.
12. Display the result array.
13. Stop

Program:

arr1 = [2, 4, 6]
arr2 = [3, 5, 7]

result = []
for i in range(len(arr1)):
[Link](arr1[i] * arr2[i])

print("Resultant array:", result)

Output:

Resultant array: [6, 20, 42]


Dictionary methods:
Aim:

To demonstrate dictionary methods in Python.


Algorithm:

14. Start
15. Create a dictionary.
16. Apply dictionary methods: keys(), values(), items(), get(), update(), pop().
17. Display results.
18. Stop

Program:

student = {"name": "Alice", "age": 20, "course":


"Python"}
print("Keys:", [Link]())
print("Values:", [Link]())
print("Items:", [Link]())

print("Get age:", [Link]("age"))


[Link]({"age": 21})
print("Updated Dictionary:", student)

[Link]("course")
print("After Pop:", student)

Output:

Keys: dict_keys(['name', 'age', 'course'])


Values: dict_values(['Alice', 20, 'Python'])
Items: dict_items([('name', 'Alice'), ('age', 20),
('course', 'Python')])
Get age: 20
Updated Dictionary: {'name': 'Alice', 'age': 21,
'course': 'Python'}
After Pop: {'name': 'Alice', 'age': 21}
List operations:
Aim:

To perform basic list operations.


Algorithm:

19. Start
20. Create a list.
21. Perform operations: append, insert, remove, sort, reverse.
22. Display results.
23. Stop

Program:

numbers = [5, 2, 9, 1]

[Link](7)
print("After Append:", numbers)

[Link](2, 4)
print("After Insert:", numbers)

[Link](9)
print("After Remove:", numbers)

[Link]()
print("After Sort:", numbers)

[Link]()
print("After Reverse:", numbers)

Output:
After Append: [5, 2, 9, 1, 7]
After Insert: [5, 2, 4, 9, 1, 7]
After Remove: [5, 2, 4, 1, 7]
After Sort: [1, 2, 4, 5, 7]
After Reverse: [7, 5, 4, 2, 1]

Flies operation:
Aim:

To demonstrate file operations in Python.


Algorithm:

24. Start
25. Open a file in write mode and write text.
26. Close the file.
27. Open the same file in read mode and read contents.
28. Display contents.
29. Stop
Program:

# Writing to a file
file = open("[Link]", "w")
[Link]("Hello, this is a file operation
example.")
[Link]()

# Reading from a file


file = open("[Link]", "r")
content = [Link]()
print("File Content:", content)
[Link]()

Output:

File Content: Hello, this is a file operation


example.
Swapping two numbers
Aim:

To swap two numbers without using a third variable.


Algorithm:

30. Start
31. Read two numbers.
32. Swap using arithmetic operations.
33. Display swapped numbers.
34. Stop

Program:

a=5
b = 10

print("Before Swap: a =", a, " b =", b)

a, b = b, a

print("After Swap: a =", a, " b =", b)

Output:

Before Swap: a = 5 b = 10
After Swap: a = 10 b = 5
Prime numbers:
Aim:

To check whether a number is prime.


Algorithm:

35. Start
36. Read a number.
37. Check divisibility from 2 to n-1.
38. If divisible, not prime.
39. Else, prime.
40. Stop

Program:
num = 29

if num > 1:
for i in range(2, num):
if num % i == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

Output:

29 is a prime number

Classes and objects


AIM:
To write a program to create a class and display details using classes in python
ALGORITHM:

Step1:start
Step2:defind a class with the name employee
Step3:create a class defind functions file-detail() to assign the values to data members such as
employee nu8mbers,employee name,salary
Step4:display the details using display() user defined function
Step5:create 3 objects using display the details of 3 employee
Step6:stop
CODE:

class Employee:
def file_details(self, a, b, c):
self.employee_number = a
self.employee_name = b
[Link] = c

def display(self):
print(self.employee_number, self.employee_name, [Link])

e1 = Employee()
e2 = Employee()
e3 = Employee()

e1.file_details(101, 'AAA', 20000)


e2.file_details(102, 'BBB', 30000)
e3.file_details(103, 'CCC', 50000)

[Link]()
[Link]()
[Link]()

class Employee:
def file_details(self, a, b, c):
self.employee_number = a
self.employee_name = b
[Link] = c
def display(self):
print(self.employee_number, self.employee_name, [Link])

e1 = Employee()
e2 = Employee()
e3 = Employee()

e1.file_details(101, 'AAA', 20000)


e2.file_details(102, 'BBB', 30000)
e3.file_details(103, 'CCC', 50000)

[Link]()
[Link]()
[Link]()

Constructors
Aim:

To write a program to check a class and to display details using constructors


ALGORITHM:

Step1:start
Step2:define a class with name product
Step3:define the constructors which initializes the values for produce name,quantity price
Step4:define the user defind function display() which is used to display the details
Step5:create 3 objects to assign and display the details of 3 pridxuts
Step6:stop
CODE:

class Product:
def __init__(self, a, b, c):
self.product_name = a
[Link] = b
[Link] = c

def display(self):
print(self.product_name, [Link], [Link])

p1 = Product('biscuit', 10, 'rs.100')


p2 = Product('juice', 15, 'rs.200')
p3 = Product('lake', 20, 'rs.500')

[Link]()
[Link]()
[Link]()
Emloyee details
AIM:

To write a program to print employee details table using sqlite


ALGORITHM:

Step1:start
Step2:import sqlite3 and correct to the database and currosr
Step3:create the table employee details with fields of eno,enname,dept,salary
Step4:insert 5 records to the table using insert command
Step5:display the results using select command and fetchall()
Step6:delete the results using select command and using delete command
Step7:display the result using select command abd fectchall()
Step8:update the salary of anyone of employee using update command
Step9:displasy the result using select command and fecchall()
Step10:stop

Code:

import sqlite3

conn = [Link]("[Link]")
c = [Link]()

[Link]("""
CREATE TABLE IF NOT EXISTS employee_details (
eno INTEGER PRIMARY KEY,
ename TEXT,
dept TEXT,
salary INTEGER
)
""")

[Link]("INSERT INTO employee_details VALUES (101, 'leebna', 'manager', 30000)")


[Link]("INSERT INTO employee_details VALUES (102, 'manisha', 'hr', 40000)")
[Link]("INSERT INTO employee_details VALUES (103, 'sanjana', 'sales manager', 50000)")
[Link]("INSERT INTO employee_details VALUES (104, 'divya', 'finance manager', 35000)")

[Link]("SELECT * FROM employee_details")


print([Link]())

[Link]("DELETE FROM employee_details WHERE eno = 101")

[Link]("SELECT * FROM employee_details")


print([Link]())

[Link]("UPDATE employee_details SET salary = 20000")

[Link]("SELECT * FROM employee_details")


print([Link]())

[Link]()
________________.

Internal Examiner External Examiner

INDEX

Ex -No Date Content Sign


1 03/07/2025 Leap year

2 03/07/2025 Days of the week

3 03/07/2025 Sum of series

4 07/07/2025 Factorial

5 11/07/2025 Multiplication Table


6 11/07/2027 Greatest of three numbers

7 18/07/2025 Fibonacci series

8 180/7/2025 Searching a character in a given string

9 22/07/2025 Array Search

10 26/07/2025 Array multiplication

11 29/07/2025 Dictionary Methods

12 04/08/2025 List operations

13 11/08/2025 File operations

14 11/08/2025 Swapping of two numbers

15 20/07/2025 Prime number

16 22/08/2025 Classes and objects

17 28/08/2025 Constructors

18 10/09/2025 Employee details

You might also like