SRI CHANDRASEKHARENDRA SARASWATHI VISWA
MAHAVIDYALAYA
(Deemed to be University Under Section 3 of UGC Act 1956)
Accredited with “A” Grade by NAAC
Enathur, Kanchipuram - 631 561.
PYTHON LAB
Laboratory Record
Name : ______________________________
Reg. No : ______________________________
Class : III BCA
Subject Code : UCAF236P60
Subject : PYTHON LAB
SRI CHANDRASEKHARENDRA SARASWATHI VISWA
MAHAVIDYALAYA
(Deemed to be University Under Section 3 of UGC Act 1956)
Accredited with “A” Grade by NAAC
Enathur, Kanchipuram - 631 561.
BONAFIDE CERTIFICATE
This is to certify that this is the Bonafide record of work done by
Mr._______________________________, with Reg. No.___________________ of
III BCA in the PYTHON LAB Laboratory during the academic year 2025-2026.
Staff-in-charge Head of the Department
Dr. U. Vageeswari Dr. V. Ramesh
Assistant Professor Associate Professor,
Department of CSA, Department of CSA,
SCSVMV. SCSVMV.
Submitted for the Practical Examination held on .
Internal Examiner External Examiner
INDEX
Exp. Date Title Page No Signature
No
Program to Check Whether a Given Number
1 20-01-26 01
is Even or Odd
Program to print decimal equivalents of
2 27-01-26 02
fractions from 1/2 to 1/10
Program to Loop Over a Sequence Using a
3 03-02-26 For Loop 03
Program to Print Count Down Using While
4 10-02-26 Loop 04
Program to Display All the Prime Numbers
5 17-02-26 05
Below a Given Range
Program to Display the Fibonacci Sequence
6 20-02-26 06
Program to Count Characters in a String
7 24-02-26 Using Dictionary 07
Program to Use Split and Join Methods and
8 03-03-26 Trace a Birthday Using Dictionary 08
Program to Combine Lists into a Dictionary
9 06-03-26 09
Program to Print Each Line of a File in
10 17-03-26 11
Reverse Order
Program to Compute Number of Characters,
11 20-03-26 Words and Lines in a File 13
Program to Perform Addition of Two
12 21-03-26 Matrices 15
GUI Program for Calculator Using Tkinter
13 24-03-26 17
Program to Draw Shapes at Different
14 31-03-26 21
Locations Using Turtle
GUI Based Python Program to Interact with
15 03-04-26 Database 25
Date: 20-01-26 Page No: 01
[Link] to Check Whether a Given Number is Even or Odd
Aim:
To write a Python program to check whether the given number is even or odd.
Procedure:
1. Start the program.
2. Read a number from the user.
3. Use the modulus operator % to divide the number by 2.
4. If the remainder is 0, the number is even.
5. Otherwise, the number is odd.
6. Display the result.
7. Stop the program.
Program:
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
Output:
Enter a number: 10
10 is Even
Enter a number: 7
7 is Odd
Result:
Thus, the Program has been Executed Successfully.
.
Date: 27-01-26 Page No: 02
[Link] to print decimal equivalents of fractions from 1/2 to 1/10
Aim:
To write a Python program using a for loop to print the decimal equivalents of 1/2, 1/3,
…, 1/10.
Procedure:
1. Start the program.
2. Use a for loop to iterate numbers from 2 to 10.
3. For each number, compute the value of 1 / number.
4. Display the fraction and its decimal value.
5. Stop the program.
Program:
for i in range(2, 11):
print("1/", i, "=", 1/i)
Output:
1 / 2 = 0.5
1 / 3 = 0.3333333333333333
1 / 4 = 0.25
1 / 5 = 0.2
1 / 6 = 0.16666666666666666
1 / 7 = 0.14285714285714285
1 / 8 = 0.125
1 / 9 = 0.1111111111111111
1 / 10 = 0.1
Result:
Thus, the Program has been Executed Successfully.
Date: 03-02-26 Page No: 03
[Link] to Loop Over a Sequence Using a For Loop
Aim:
To write a Python program to loop over a sequence using a for loop and display the
elements.
Procedure:
1. Start the program.
2. Get the number of elements (n) from the user.
3. Read n elements and store them in a list.
4. Use a for loop to iterate through the list.
5. Display each element.
6. Stop the program.
Program:
n = int(input("Enter the number of elements: "))
lst = []
print("Enter the elements:")
for i in range(n):
val = input()
[Link](val)
print("Elements in the list are:")
for item in lst:
print(item)
Output:
Enter the number of elements: 3
Enter the elements:
10
20
30
Elements in the list are:
10
20
30
Result: Thus, the Program has been Executed Successfully.
Date:10-02-26 Page No: 04
[Link] to Print Count down Using While Loop
Aim:
To write a Python program to print a countdown from a given number to zero using a
while loop.
Procedure:
1. Start the program.
2. Read a number from the user.
3. Use a while loop to check if the number is greater than or equal to 0.
4. Print the current number.
5. Decrease the number by 1 in each iteration.
6. Repeat until the number becomes less than 0.
7. Stop the program.
Program:
num = int(input("Enter a number: "))
while num >= 0:
print(num)
num = num – 1
Output:
Enter a number: 5
5
4
3
2
1
0
Result:
Thus, the Program has been Executed Successfully.
Date: 17-02-26 Page No: 05
[Link] to Display All the Prime Numbers Below a Given Range
Aim:
To write a Python program to display all the prime numbers below a given range.
Procedure:
1. Start the program.
2. Read the limit (range) from the user.
3. Use a loop to check numbers from 2 to the given range.
4. For each number, check whether it is prime.
5. If the number is prime, display it.
6. Repeat until all numbers are checked.
7. Stop the program.
Program:
n = int(input("Enter the range: "))
print("Prime numbers are:")
for num in range(2, n):
is_prime = True
for i in range(2, num):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num)
Output:
Enter the range: 10
Prime numbers are:
2
3
5
7
Result:
Thus, the Program has been Executed Successfully.
Date: 20-02-26 Page No: 06
[Link] to Display the Fibonacci Sequence
Aim:
To write a Python program to display the Fibonacci sequence.
Procedure:
1. Start the program.
2. Read the number of terms (n) from the user.
3. Initialize the first two terms as 0 and 1.
4. Display the first two terms.
5. Use a loop to generate the next terms by adding the previous two numbers.
6. Repeat until n terms are displayed.
7. Stop the program.
Program:
n = int(input("Enter number of terms: "))
a=0
b=1
print("Fibonacci sequence:")
for i in range(n):
print(a)
c=a+b
a=b
b=c
Output:
Enter number of terms: 5
Fibonacci sequence:
0
1
1
2
3
Result:
Thus, the Program has been Executed Successfully.
Date:24-02-26 Page No: 07
[Link] to Count Characters in a String Using Dictionary
Aim:
To write a Python program to count the number of characters in a string and store them
in a dictionary.
Procedure:
1. Start the program.
2. Read a string from the user.
3. Create an empty dictionary.
4. Traverse each character in the string.
5. If the character is already in the dictionary, increase its count.
6. Otherwise, add the character to the dictionary with count 1.
7. Display the dictionary.
8. Stop the program.
Program:
s = input("Enter a string: ")
d1 = {}
for ch in s:
if ch in d1:
d1[ch] += 1
else:
d1[ch] = 1
print("Character count:", d1)
Output:
Enter a string: hello
Character count: {'h': 1, 'e': 1, 'l': 2, 'o': 1}
Result:
Thus, the Program has been Executed Successfully.
Date: 03-03-26 Page No: 08
[Link] to Use Split and Join Methods and Trace a Birthday Using Dictionary
Aim:
To write a Python program to use split and join methods in a string and trace a birthday
using a dictionary.
Procedure:
1. Start the program.
2. Create an empty dictionary.
3. Read a string in the format name-dd-mm-yyyy.
4. Use the split() method to separate the string using “-”.
5. Extract the name and date parts.
6. Use the join() method to combine the date using “/”.
7. Store the name and formatted date in the dictionary.
8. Display the dictionary.
9. Stop the program.
Program:
d1 = {}
s = input("Enter a string in format name-dd-mm-yyyy: ")
l1 = [Link]("-")
ch = l1[0]
[Link](ch)
s1 = "/".join(l1)
d1[ch] = s1
print("The Result is :", d1)
Output:
Enter a string in format name-dd-mm-yyyy: Sarathy-23-10-2005
The Result is : {'Sarathy': '23/10/2005'}
Result:
Thus, the Program has been Executed Successfully.
Date: 06-03-26 Page No: 09
[Link] to Combine Lists into a Dictionary
Aim:
To write a Python program to combine two lists into a dictionary.
Procedure:
1. Start the program.
2. Read the number of elements (n) from the user.
3. Read n elements for the first list (keys).
4. Read n elements for the second list (values).
5. Use a loop to combine both lists into a dictionary.
6. Display the dictionary.
7. Stop the program.
Program:
n = int(input("Enter number of elements: "))
list1 = []
list2 = []
print("Enter elements for first list (keys):")
for i in range(n):
[Link](input())
print("Enter elements for second list (values):")
for i in range(n):
[Link](input())
d1 = {}
for i in range(n):
d1[list1[i]] = list2[i]
print("Combined Dictionary:", d1)
Output:
Enter number of elements: 3
Enter elements for first list (keys):
a
b
c
Enter elements for second list (values):
1
2
3
Combined Dictionary: {'a': '1', 'b': '2', 'c': '3'}
Result:
Thus, the Program has been Executed Successfully.
Date: 17-03-26 Page No:11
[Link] to Print Each Line of a File in Reverse Order
Aim:
To write a Python program to read a file and print each line in reverse order.
Procedure:
1. Start the program.
2. Create a function to write data into a file.
3. Create another function to read the file.
4. Read all lines from the file using readlines().
5. Remove newline characters using strip().
6. Reverse each line using slicing [::-1].
7. Display the reversed lines.
8. Use a menu to perform write, read-reverse, and exit operations.
9. Stop the program.
Program:
def store():
f1 = open("e:/[Link]", "a")
str1 = input("Enter a string: ")
[Link](str1 + "\n")
[Link]()
def rev():
f1 = open("e:/[Link]", "r")
L1 = [Link]()
for L in L1:
L = [Link]("\n")
print(L[::-1])
[Link]()
#------- Main Program----------------
while True:
print("[Link]")
print("[Link] and Reverse")
print("[Link]")
ch = int(input("Enter your choice: "))
if ch == 1:
store()
elif ch == 2:
rev()
else:
break
Output:
[Link]
[Link] and Reverse
[Link]
Enter your choice: 1
Enter a string: hello
Enter your choice: 1
Enter a string: world
Enter your choice: 2
olleh
dlrow
Result:
Thus, the Program has been Executed Successfully.
Date: 20-03-26 Page No: 13
[Link] to Compute Number of Characters, Words and Lines in a File
Aim:
To write a Python program to count the number of characters, words, and lines in a file.
Procedure:
1. Start the program.
2. Create a function to write data into a file.
3. Create another function to read the file.
4. Read all lines using readlines().
5. Count the number of lines.
6. Count characters by iterating through each character.
7. Count words by counting spaces and adding one for each line.
8. Display the number of lines, words, and characters.
9. Stop the program.
Program:
def store():
f1 = open("e:/[Link]", "a")
str1 = input("Enter a string: ")
[Link](str1 + "\n")
[Link]()
def count1():
f1 = open("e:/[Link]", "r")
L1 = [Link]()
lines, words, char = 0, 0, 0
for L in L1:
lines = lines + 1
L = [Link]("\n")
for c in L:
char = char + 1
if c == " ":
words = words + 1
words = words + 1
print("Lines:", lines)
print("Words:", words)
print("Characters:", char)
[Link]()
#------- Main Program----------------
while True:
print("[Link]")
print("[Link]")
print("[Link]")
ch = int(input("Enter your choice: "))
if ch == 1:
store()
elif ch == 2:
count1()
else:
break
Output:
[Link]
[Link]
[Link]
Enter your choice: 1
Enter a string: Hello world
Enter your choice: 1
Enter a string: Python program
Enter your choice: 2
Lines: 2
Words: 4
Characters: 23
Result:
Thus, the Program has been Executed Successfully.
Date:21-03-26 Page No: 15
[Link] to Perform Addition of Two Matrices
Aim:
To write a Python program to perform addition of two matrices by accepting rows,
columns, and elements from the user.
Procedure:
1. Start the program.
2. Read number of rows and columns from the user.
3. Initialize matrices A and B.
4. Read elements for matrix A.
5. Read elements for matrix B.
6. Add corresponding elements of both matrices.
7. Display the resultant matrix in matrix form.
8. Stop the program.
Program:
m = int(input("Enter number of rows: "))
n = int(input("Enter number of columns: "))
A = []
B = []
C = []
print("Enter elements of Matrix A:")
for i in range(m):
row = []
for j in range(n):
[Link](int(input()))
[Link](row)
print("Enter elements of Matrix B:")
for i in range(m):
row = []
for j in range(n):
[Link](int(input()))
[Link](row)
for i in range(m):
row = []
for j in range(n):
temp = A[i][j] + B[i][j]
[Link](temp)
[Link](row)
print("Resultant Matrix:")
for i in range(m):
for j in range(n):
print(C[i][j], end=" ")
print()
Output:
Enter number of rows: 2
Enter number of columns: 2
Enter elements of Matrix A:
1
2
3
4
Enter elements of Matrix B:
5
6
7
8
Resultant Matrix:
6 8
10 12
Result:
Thus, the Program has been Executed Successfully.
Date:24-03-26 Page No:17
[Link] Program for Calculator Using Tkinter
Aim:
To write a Python program to design a GUI-based expression calculator using Tkinter
for performing addition, subtraction, multiplication, and division.
Procedure:
1. Start the program.
2. Import the tkinter module.
3. Define functions for addition, subtraction, multiplication, and division.
4. In each function, read values from the textboxes, perform the operation, and display
the result.
5. Create the main window using Tk().
6. Create frames for organizing rows.
7. Add labels and textboxes for two numbers and result.
8. Create buttons for each operation and link them to respective functions.
9. Arrange all widgets using pack() method with left alignment.
10. Run the application using mainloop().
11. Stop the program.
Program:
import tkinter as tk
def add():
result = int([Link]()) + int([Link]())
[Link](0,[Link])
[Link](0,result)
def sub():
result = int([Link]()) - int([Link]())
[Link](0,[Link])
[Link](0,result)
def mul():
result = int([Link]()) * int([Link]())
[Link](0,[Link])
[Link](0,result)
def div():
result = int([Link]()) / int([Link]())
[Link](0,[Link])
[Link](0,result)
#-------------------Main Program--------------------
root = [Link]()
[Link]("Calculator")
# ---------------------Row 1-------------------
f1 = [Link](root)
[Link](anchor="w")
l1 = [Link](f1, text="Number 1 ")
[Link](side="left")
t1 = [Link](f1)
[Link](side="left")
# ----------------------------Row 2-------------------
f2 = [Link](root)
[Link](anchor="w")
l2 = [Link](f2, text="Number 2 ")
[Link](side="left")
t2 = [Link](f2)
[Link](side="left")
#----------------------- Row 3-------------------
f3 = [Link](root)
[Link](anchor="w")
l3 = [Link](f3, text="Result ")
[Link](side="left")
t3 = [Link](f3)
[Link](side="left")
# -------------------Row 4 (Buttons)-------------------------
f4 = [Link](root)
[Link](anchor="w")
b1 = [Link](f4, text="Addition", command=add)
[Link](side="left")
b2 = [Link](f4, text="Subtraction", command=sub)
[Link](side="left")
b3 = [Link](f4, text="Multiplication", command=mul)
[Link](side="left")
b4 = [Link](f4, text="Division", command=div)
[Link](side="left")
[Link]()
Output:
Form Design:
Addition:
Subtraction:
Multiplication:
Division:
Result:
Thus, the Program has been Executed Successfully.
Date: 31-03-26 Page No: 21
[Link] to Draw Shapes at Different Locations Using Turtle
Aim:
To write a Python program to draw a line, square, rectangle, triangle, and circle with
colors using the Turtle module.
Procedure:
1. Start the program.
2. Import the turtle module.
3. Disable animation using tracer(0).
4. Create a turtle object and set pen size.
5. Move the turtle to different positions using goto().
6. Set color and fill color for each shape.
7. Use loops to draw square, rectangle, and triangle.
8. Use circle() to draw the circle.
9. Use begin_fill() and end_fill() to fill shapes.
10. Update the screen using update().
11. Stop the program.
Program:
import turtle
t = [Link]()
[Link](0)
[Link](5)
# --------------Line-------
[Link](5)
len=150
[Link](len)
# ---------Circle---------
[Link]()
[Link](200,100)
[Link]()
r = 100
[Link](r)
# ---------Square---------
[Link]()
s = 150
[Link](200,-170)
[Link]()
# drawing first side
[Link](s)
[Link](90)
# drawing second side
[Link](s)
[Link](90)
# drawing third side
[Link](s)
[Link](90)
# drawing fourth side
[Link](s)
[Link](90)
# ---------Rectangle---------
[Link]()
[Link](-300, 100)
[Link]()
l = 300
b = 150
# first side
[Link](l)
[Link](90)
# second side
[Link](b)
[Link](90)
# third side
[Link](l)
[Link](90)
# fourth side
[Link](b)
[Link](90)
# ---------Triangle---------
[Link]()
[Link]("red")
[Link](-200, -100)
[Link]()
t.begin_fill()
s = 150
# first side
[Link](s)
[Link](120)
# second side
[Link](s)
[Link](120)
# third side
[Link](s)
[Link](120)
t.end_fill()
[Link]()
[Link]()
Output:
Result:
Thus, the Program has been Executed Successfully.
Date:03-04-26 Page No: 25
[Link] Based Python Program to Interact with Database
Aim:
To write a Python program to perform database operations such as create, insert, update,
delete, and select using Tkinter and SQLite.
Procedure:
1. Start the program.
2. Import required modules: tkinter, messagebox, and sqlite3.
3. Create a function to create a table in the database.
4. Create functions to insert, update, delete, and select records.
5. Use Entry widgets to accept employee ID and name.
6. Use buttons to perform database operations.
7. Display messages using messagebox for each operation.
8. In select operation, fetch records and display them one by one.
9. Run the GUI using mainloop().
10. Stop the program.
Program:
import tkinter as tk
from tkinter import messagebox
import sqlite3
def create_table():
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("CREATE TABLE IF NOT EXISTS employee(empid INTEGER
PRIMARY KEY,empname TEXT)")
[Link]()
[Link]()
[Link]("Information","Table created successfully")
def insert_record():
import sqlite3
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("INSERT INTO employee (empid, empname) VALUES (?, ?)",
[int([Link]()), [Link]()])
[Link]()
[Link]()
[Link]("","Table inserted successfully")
def update_record():
import sqlite3
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("update employee set empname=? where empid = ?",
[[Link](), int([Link]())])
[Link]()
[Link]()
[Link]("","Table updated successfully")
def delete_record():
import sqlite3
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("delete from employee where empid = ?", [int([Link]())])
[Link]()
[Link]()
[Link]("","Table deleted successfully")
def select_record():
import sqlite3
conn = [Link]("[Link]")
cursor = [Link]()
[Link]("select * from employee")
rows = [Link]()
for row in rows:
[Link](0,[Link])
[Link](0,[Link])
[Link](0,row[0])
[Link](0,row[1])
[Link]("","Next record")
[Link]()
[Link]()
#-------------Main Program--------------------
root = [Link]()
[Link]("Database Application")
#------Main frame-------
frame = [Link](root)
[Link](anchor="w")
f1 = [Link](frame)
[Link](anchor="w")
#----------Row1 frame ------
l1 = [Link](f1, text="Employee ID ")
[Link](side="left")
t1 = [Link](f1)
[Link](side="left")
#---------Row 2 frame--------
f2 = [Link](frame)
[Link](anchor="w")
l2 = [Link](f2, text="Employee Name ")
[Link](side="left")
t2 = [Link](f2)
[Link](side="left")
#----------Row 3 frame---------
f3 = [Link](frame)
[Link](anchor="w")
b1 = [Link](f3, text="Create", command=create_table)
[Link](side="left")
b2 = [Link](f3, text="Insert", command=insert_record)
[Link](side="left")
b3 = [Link](f3, text="Update", command=update_record)
[Link](side="left")
b4 = [Link](f3, text="Delete", command=delete_record)
[Link](side="left")
b5 = [Link](f3, text="Select", command=select_record)
[Link](side="left")
[Link]()
Output:
Form Design:
Table Creation:
Insertion of Record:
Updation of Record:
Deletion of Record:
Display of Record:
Result:
Thus, the Program has been Executed Successfully.