NANDHA ARTS AND SCIENCE COLLEGE
(AUTONOMOUS)
ERODE – 52
DEPARTMENT OF COMPUTER TECHNOLOGY
RECORD NOTEBOOK
PROBLEM SOLVING USING PYTHON LAB
NAME :
REGISTERNO. :
CLASS : [Link](CT)
NANDHA ARTS AND SCIENCE COLLEGE
(AUTONOMOUS)
ERODE – 52
BACHELOR OF SCIENCE(COMPUTERTECHNOLOGY)
This is to certified that the bonafide record of practical work done by
[Link] during the
academic year 2025-26.
Staff In-charge Head of the Department
Submitted for the Bharathiar University practical examination held on
in the Department of Computer Technology in Nandha Arts and Science College, Erode-52.
INTERNAL EXAMINER EXTERNAL EXAMINER
CONTENTS
[Link] DATE LIST OF THE EXPERIMENTS PAGE SIGNATURE
No
1
ARITHMETIC OPERATIONS
2
MULTIPLY MATRICES USING
LOOP
3 STUDENT MARK SHEET
PREPARATION USING DECISION
MAKING STATEMENT
4 SLICE OPERATIONS
5 DICTIONARY OPERATIONS
FILTER EVEN NUMBERS USING
6 FUNCTIONS & LAMDA FUNCTIONS
7 TEXT AND SHAPES ON A CANVAS
8 MENU BAR USING TKINTER
[Link] : 1
ARITHMETIC OPERATIONS
DATE :
AIM:
ALGORITHM:
SOURCE CODE:
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
result = a + b
print(f"The result of addition is: {result}")
result1 = a - b
print(f"The result of subtraction is: {result1}")
result2 = a * b
print(f"The result of multiplication is: {result2}")
if b != 0:
result = a / b
print(f"The result of division is: {result}")
else:
print("Error: Division by zero is not allowed.")
OUTPUT:
Enter the first number:67
Enter the second number:56
The result of addition is:123.0
The result of subtraction is:11.0
The result of multiplication is:3752.0
The result of division is:1.196428
RESULT
Thus the Python program was executed and the output is verified.
[Link] : 2
MULTIPLY MATRICES USING LOOP
DATE :
AIM:
ALGORITHM:
SOURCE CODE:
X = [[2,7],[4 ,5]]
Y = [[5,8],[6,7]]
result = [[0,0],[0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
OUTPUT:
[52, 65]
[50, 67]
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 3 STUDENT MARK SHEET PREPARATION USING
DATE : DECISION MAKING STATEMENT
AIM:
ALGORITHM:
SOURCE CODE:
def calculate_grade(average):
if average >= 90:
return "A"
elif average >= 70:
return "B"
elif average >= 50:
return "C"
else:
return "D"
def st_marksheet():
print("Enter marks for the following subjects out of 100:")
t= float(input("Tamil: "))
e = float(input("English: "))
d = float(input("Database: "))
p = float(input("Python: "))
m = float(input("Maths: "))
total = t+e+d+p+m
average_marks = total/5
grade = calculate_grade(average_marks)
print("\n--------- Mark Sheet ---------")
print(f"Tamil: {t}")
print(f"English: {e}")
print(f"Database: {d}")
print(f"Python: {p}")
print(f"Maths: {m}")
print(f"Total Marks: {total}")
print(f"Average Marks: {average_marks:.2f}")
print(f"Grade: {grade}")
st_marksheet()
OUTPUT:
Enter marks for the following subjects out of 100:
Tamil: 79
English: 89
Database: 80
Python: 98
Maths: 80
--------- Mark Sheet ---------
Tamil: 79.0
English: 89.0
Database: 80.0
Python: 98.0
Maths: 80.0
Total Marks: 426.0
Average Marks: 85.20
Grade: B
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 4
SLICE OPERATIONS
DATE :
AIM:
ALGORITHM:
SOURCE CODE:
sl = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# Step 2: Basic slicing
print("Original list:", sl)
print("Slice from index 2 to 5:", sl[2:6])
print("Slice from the beginning to index 3:", sl[:4])
print("Slice from index 5 to the end:", sl[5:])
# Step 3: Slicing with steps
print("Slice every second element (step=2):", sl[::2])
print("Slice every third element (step=3):", sl[::3])
# Step 4: Slicing in reverse
print("Reverse the list:", sl[::-1])
print("Reverse slice from index -2 to -6:", sl[-2:-6:-1])
# Step 5: Special cases
print("Entire list using [:]:", sl[:])
print("Last 3 elements:", sl[-3:])
print("First 5 elements in reverse:", sl[4::-1])
OUTPUT:
Original list: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Slice from index 2 to 5: [30, 40, 50, 60]
Slice from the beginning to index 3: [10, 20, 30, 40]
Slice from index 5 to the end: [60, 70, 80, 90, 100]
Slice every second element (step=2): [10, 30, 50, 70, 90]
Slice every third element (step=3): [10, 40, 70, 100]
Reverse the list: [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
Reverse slice from index -2 to -6: [90, 80, 70, 60]
Entire list using [:]: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Last 3 elements: [80, 90, 100]
First 5 elements in reverse: [50, 40, 30, 20, 10]
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 5
DICTIONARY OPERATIONS
DATE :
AIM:
ALGORITHM:
SOURCE CODE:
# Step 1: Define a dictionary
my_dict = {"name": "John","age": 25,"city": "New York"}
print("Original dictionary:", my_dict)
# Step 2: Add new items to the dictionary
my_dict["profession"] = "Engineer" # Adding a new key-value pair
my_dict["hobby"] = "Photography" # Adding another key-value pair
print("\n After adding new items:", my_dict)
# Step 3: Modify existing items in the dictionary
my_dict["age"] = 30 # Modifying the value of an existing
key
my_dict["city"] = "San Francisco" # Changing the value of another key
print("\n After modifying existing items:", my_dict)
# Step 4: Add or update multiple items using update()
my_dict.update({"country": "USA", "name": "Jonathan"})
print("\n After adding/updating multiple items using update():", my_dict)
OUTPUT:
Original dictionary: {'name': 'John', 'age': 25, 'city': 'New York'}
After adding new items: {'name': 'John', 'age': 25, 'city': 'New York',
'profession': 'Engineer', 'hobby': 'Photography'}
After modifying existing items: {'name': 'John', 'age': 30, 'city': 'San
Francisco', 'profession': 'Engineer', 'hobby': 'Photography'}
After adding/updating multiple items using update(): {'name': 'Jonathan',
'age': 30, 'city': 'San Francisco', 'profession': 'Engineer', 'hobby': 'Photography',
'country': 'USA'}
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 6
DATE :
FILTER EVEN NUMBERS USING FUNCTIONS & LAMDA
FUNCTIONS
AIM:
ALGORITHM:
SOURCE CODE:
#Using normal function
numbers=[1,2,3,4,5,6,7,8,9,10]
def is_even(x):
return x%2==0
even_numbers_function=filter(is_even,numbers)
print("Even Numbers are:",list(even_numbers_function))
OUTPUT:
Even Number is: [2, 4, 6, 8, 10]
#Using lambda function
numbers=[1,2,3,4,5,6,7,8,9,10]
even_numbers_lambda=filter(lambda x:x%2==0,numbers)
print("Even Number is:",list(even_numbers_lambda))
OUTPUT:
Even Number is: [2, 4, 6, 8, 10]
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 7
TEXT AND SHAPES ON A CANVAS
DATE :
AIM:
ALGORITHM:
SOURCE CODE:
import tkinter as tk
from tkinter import font
# Step 1: Create the main window
root = [Link]()
[Link]("Font and Shapes Example")
# Step 2: Create a canvas widget inside the window
canvas = [Link](root, width=500, height=500, bg="white")
[Link]()
# Step 3: Change the font of the text
# Define the font (family, size, style)
text_font = [Link](family="Helvetica", size=20, weight="bold", slant="italic")
# Display the text on the canvas with the specified font
canvas.create_text(250, 50, text="Hello, World!", font=text_font, fill="blue")
# Step 4: Draw colored shapes
# Draw a rectangle with red color
canvas.create_rectangle(50, 100, 200, 200, fill="red")
# Draw an oval with green color
canvas.create_oval(250, 100, 450, 200, fill="green")
# Draw a polygon with blue color
points = (
(100, 300),
(200, 200),
(300, 300),
)
canvas.create_polygon(*points, fill='blue')
# Step 5: Run the Tkinter event loop to display the window
[Link]()
OUTPUT:
RESULT:
Thus the Python program was executed and the output is verified.
[Link] : 8
MENU BAR USING TKINTER
DATE :
AIM
ALGORITHM:
SOURCE CODE:
import tkinter as tk
from tkinter import messagebox
# Create the main window
root = [Link]()
[Link]("Menu on Menubar")
# Function to display a message box
def show_message():
[Link]("Information", "Menu item clicked!")
# Create a menubar
menubar = [Link](root)
# Create a File menu
file_menu = [Link](menubar, tearoff=0)
file_menu.add_command(label="New", command=show_message)
file_menu.add_command(label="Open", command=show_message)
file_menu.add_command(label="Save", command=show_message)
file_menu.add_command(label="Save as", command=show_message)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=[Link])
menubar.add_cascade(label="File", menu=file_menu)
# Create an Edit menu
edit_menu = [Link](menubar, tearoff=0)
edit_menu.add_command(label="Cut", command=show_message)
edit_menu.add_command(label="Copy", command=show_message)
edit_menu.add_command(label="Paste", command=show_message)
menubar.add_cascade(label="Edit", menu=edit_menu)
# Create a Help menu
help_menu = [Link](menubar, tearoff=0)
help_menu.add_command(label="About", command=show_message)
menubar.add_cascade(label="Help", menu=help_menu)
# Attach the menubar to the root window
[Link](menu=menubar)
# Run the main loop
[Link]()
OUTPUT:
RESULT:
Thus the Python program was executed and the output is verified.