TAKSHASHILA UNIVERSITY
Tamil Nadu State Private University
( Established under Tamil Nadu State Private Universities Act 2019
& Recognized by UGC u/s 2(f) of the UGC Act,1956 )
Ongur, Tindivanam Taluk, Villupuram District, Tamil Nadu – 604305.
FACULTY OF SCIENCES
SCHOOL OF COMPUTER SCIENCE
STUDENT RECORD
REGISTER NUMBER : _______________________________________________
NAME OF THE STUDENT : _______________________________________________
PROGRAM NAME : _______________________________________________
YEAR / SEMESTER : _______________________________________________
COURSE CODE : _______________________________________________
COURSE NAME : _______________________________________________
TAKSHASHILA UNIVERSITY
Tamil Nadu State Private University
( Established under Tamil Nadu State Private Universities Act 2019
& Recognized by UGC u/s 2(f) of the UGC Act,1956 )
Ongur, Tindivanam Taluk, Villupuram District, Tamil Nadu – 604305.
FACULTY OF SCIENCES
School of Computer Science
Bonafide Certificate
Register Number
This is to certify that this is a Bonafide Record of practical work
done by Mr./Ms. ……….………………………………………… a
Student of BCA Computer Applications, Second Semester in
School of Computer Science, has successfully completed the
U25CA01B –Programming with Python Laboratory during the
academic year 2025-2026.
Signature of Subject Signature of School Incharge
Submitted the University Practical Examination held on ……………………….
Signature Internal Examiner Signature External Examiner
INDEX PAGE
S.N
DATE PROGRAM SIGNATURE
O
1 CALCULATOR
2 STRING FUNCTIONS
3 SELECTION SORT
4 STACK OPERATION
5 READ AND WRITE INTO FILE
DICTIONARIES
6
7 CSV FILE
8 SQL SELECT
SQL INNER JOIN
9
10 EXCEPTIONS IN PYTHON
Program
defadd(n1, n2):
return n1 + n2
defsub(n1, n2):
return n1 - n2
defmul(n1, n2):
return n1 * n2
defdiv(n1, n2):
return n1 / n2
while True:
print("Please select operation -\n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")
sel = int(input("Select operation (1-4): "))
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
if sel == 1:
print(n1, "+", n2, "=", add(n1, n2))
elifsel == 2:
print(n1, "-", n2, "=", sub(n1, n2))
elifsel == 3:
print(n1, "*", n2, "=", mul(n1, n2))
elifsel == 4:
print(n1, "/", n2, "=", div(n1, n2))
else:
print("Invalid input")
choice = input("Do you want to continue? (yes/no): ").lower()
if choice == "no":
print("Calculator exited.")
break
Output
Please select operation -
1. Add
2. Subtract
3. Multiply
4. Divide
Select operation (1-4): 1
Enter first number: 10
Enter second number: 5
10 + 5 = 15
Do you want to continue? (yes/no): no
Calculator exited.
Program
a = input("enter the string:")
print("you are enter string:", a)
print("total length of string:", len(a))
if ([Link]()):
print("converting string:", [Link]())
elif ([Link]()):
print("converting string:", [Link]())
else:
print("invalid")
print("original:", a)
print("length of the string", len(a))
print("lowercase:", [Link]())
print("uppercase:", [Link]())
print("title case:", [Link]())
print("capitalize:", [Link]())
trimtext = [Link]()
print("strip spaces:", trimtext)
print("find 'program':", [Link]("program"))
print("count of 'a':", [Link]("a"))
print("replaceword:", [Link]("python", "java"))
word = [Link]()
print("join:", "-".join(word))
Output
enter the string: python programming
you are enter string: python programming
total length of string: 18
converting string: PYTHON PROGRAMMING
original: python programming
length of the string 18
lowercase: python programming
uppercase: PYTHON PROGRAMMING
title case: Python Programming
capitalize: Python programming
strip spaces: python programming
find 'program': 7
count of 'a': 1
replaceword: java programming
join: python-programming
Program
defselection_sort(a):
for i in range(len(a)):
m=i
for j in range(i + 1, len(a)):
if a[j] < a[m]:
m=j
a[i], a[m] = a[m], a[i]
numbers = [64, 25, 12, 22, 11]
print("ARRAY BEFORE SORTING:")
print(numbers)
print("ARRAY AFTER SORTING USING SELECTION SORT:")
selection_sort(numbers)
print(numbers)
Output
ARRAY BEFORE SORTING:
[64, 25, 12, 22, 11]
ARRAY AFTER SORTING USING SELECTION SORT:
[11, 12, 22, 25, 64]
Program
# Stack implementation using list
stack = []
# Push operation
defpush():
element = input("Enter element to push: ")
[Link](element)
print(element, "pushed into stack")
# Pop operation
defpop():
if len(stack) == 0:
print("Stack is empty")
else:
print("Popped element is:", [Link]())
# Display stack
defdisplay():
if len(stack) == 0:
print("Stack is empty")
else:
print("Stack elements are:", stack)
# Main program
while True:
print("\[Link] [Link] [Link] [Link]")
choice = int(input("Enter your choice: "))
if choice == 1:
push()
elif choice == 2:
pop()
elif choice == 3:
display()
elif choice == 4:
print("Exiting program")
break
else:
print("Invalid choice")
Output
[Link] [Link] [Link] [Link]
Enter your choice: 1
Enter element to push: 10
10 pushed into stack
[Link] [Link] [Link] [Link]
Enter your choice: 1
Enter element to push: 20
20 pushed into stack
[Link] [Link] [Link] [Link]
Enter your choice: 3
Stack elements are: ['10', '20']
[Link] [Link] [Link] [Link]
Enter your choice: 2
Popped element is: 20
[Link] [Link] [Link] [Link]
Enter your choice: 4
Exiting program
Program
# Write into file
with open("D:\[Link]", "w") as file:
[Link]("Hello\n")
[Link]("This is Python program\n")
# Read from file
with open("D:\[Link]", "r") as file:
content = [Link]()
print("File Content:")
print(content)
Output
File Content:
Hello
This is Python program
Program
# Create dictionary
student = {
"Name": "Ravi",
"Age": 20,
"Course": "BCA"
}
# Access value
print("Name:", student["Name"])
# Add new item
student["Marks"] = 85
# Update value
student["Age"] = 21
# Print dictionary before deleting
print("Dictionary before deleting:", student)
# Delete item
del student["Course"]
# Check key
if "Marks" in student:
print("Marks is present")
# Display dictionary after deletion
print("Dictionary after deleting:", student)
# Loop through dictionary
for key, value in [Link]():
print(key, ":", value)
Output
Name: Ravi
Dictionary before deleting: {'Name': 'Ravi', 'Age': 21, 'Course': 'BCA', 'Marks':
85}
Marks is present
Dictionary after deleting: {'Name': 'Ravi', 'Age': 21, 'Marks': 85}
Name : Ravi
Age : 21
Marks : 85
Program
import csv
# Data to write into CSV
data = [
["Name", "Age", "Course"],
["Ravi", 20, "BCA"],
["Anu", 21, "BSc"],
["John", 22, "BCom"]
]
# Create and write CSV file
with open("[Link]", "w", newline="") as file:
writer = [Link](file)
[Link](data)
print("CSV file created successfully!\n")
# Read CSV file into list (internal data structure)
with open("[Link]", "r") as file:
reader = [Link](file)
data_list = list(reader)
# Display data
print("Data from CSV file:")
for row in data_list:
print(row)
Output
CSV file created successfully!
Data from CSV file:
['Name', 'Age', 'Course']
['Ravi', '20', 'BCA']
['Anu', '21', 'BSc']
['John', '22', 'BCom']
Program
data = [
{"id": 1, "name": "Abinaya", "age": 25, "city": "Chennai"},
{"id": 2, "name": "Bala", "age": 30, "city": "Mumbai"},
{"id": 3, "name": "Charlie", "age": 35, "city": "Chennai"},
{"id": 4, "name": "David", "age": 28, "city": "Delhi"}
]
defselect_query(query, data):
query = [Link]()
# Split WHERE
if "WHERE" in query:
select_part, where_part = [Link]("WHERE")
field, value = where_part.strip().split("=")
field = [Link]().lower()
value = [Link]().strip("'").lower()
else:
select_part = query
field = value = None
# Get columns
columns = select_part.replace("SELECT", "").strip().split(",")
columns = [[Link]().lower() for col in columns]
result = []
for row in data:
# WHERE check
if field:
if str([Link](field)).lower() != value:
continue
# SELECT columns
if columns == ["*"]:
[Link](row)
else:
[Link]({col: row[col] for col in columns})
return result
print(select_query("SELECT *", data))
print(select_query("SELECT name, age", data))
print(select_query("SELECT name WHERE city = 'Chennai'", data))
Output
[{'id': 1, 'name': 'Abinaya', 'age': 25, 'city': 'Chennai'}, {'id': 2, 'name': 'Bala', 'age':
30, 'city': 'Mumbai'}, {'id': 3, 'name': 'Charlie', 'age': 35, 'city': 'Chennai'}, {'id': 4,
'name': 'David', 'age': 28, 'city': 'Delhi'}]
[{'name': 'Abinaya', 'age': 25}, {'name': 'Bala', 'age': 30}, {'name': 'Charlie', 'age':
35}, {'name': 'David', 'age': 28}]
[{'name': 'Abinaya'}, {'name': 'Charlie'}]
Program
employees = {
1: {"name": "Alwin", "dept_id": 101},
2: {"name": "Balaji", "dept_id": 102},
3: {"name": "Charlie", "dept_id": 103},
4: {"name": "David", "dept_id": 101}
}
departments = {
101: "HR",
102: "IT",
104: "Finance"
}
result = []
for emp_id, emp in [Link]():
dept_id = emp["dept_id"]
if dept_id in departments: # INNER JOIN condition
row = {
"emp_id": emp_id,
"name": emp["name"],
"dept_id": dept_id,
"dept_name": departments[dept_id]
}
[Link](row)
for r in result:
print(r)
Output
{'emp_id': 1, 'name': 'Alwin', 'dept_id': 101, 'dept_name': 'HR'}
{'emp_id': 2, 'name': 'Balaji', 'dept_id': 102, 'dept_name': 'IT'}
{'emp_id': 4, 'name': 'David', 'dept_id': 101, 'dept_name': 'HR'}
Program
# Program to demonstrate try, except, else and finally in Python
try:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
result = a / b
exceptZeroDivisionError:
print("Error: Division by zero is not allowed.")
exceptValueError:
print("Error: Invalid input.")
except TypeError:
print("Error: Type mismatch occurred.")
else:
print("Result:", result)
finally:
print("Program execution completed.")
Output
Enter first number: 10
Enter second number: 5
Result: 2.0
Program execution completed.
Enter first number: 2
Enter second number: 0
ERROR!
Error: Division by zero is not allowed.
Program execution completed.
Enter first number: a
ERROR!
Error: Invalid input.
Program execution completed.