Program1:- Write a program in Python to input a number from the user
and calculate if the given number is prime or not.
# Function to check if a number is prime
def is_prime(number):
if number <= 1:
return False # Numbers less than or equal to 1 are not prime
for i in range(2, int(number ** 0.5) + 1): # Check divisibility up to the square root of
the number
if number % i == 0:
return False # If divisible by any number, it's not prime
return True # If no divisors were found, it's prime
# Input from the user
num = int(input("Enter a number: "))
# Check if the number is prime
if is_prime(num):
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
OUTPUT
Program2:- Write a program in Python to input a string from the user and
find out if the given string is palindrome or not.
# Function to check if a string is palindrome
def is_palindrome(s):
# Remove spaces and convert to lowercase for case insensitive comparison
s = [Link](" ", "").lower()
# Check if the string is equal to its reverse
return s == s[::-1]
# Input from the user
user_input = input("Enter a string: ")
# Check if the string is a palindrome
if is_palindrome(user_input):
print(f"'{user_input}' is a palindrome.")
else:
print(f"'{user_input}' is not a palindrome.")
OUTPUT
Program3:- Write a program in Python, which inputs a list L of integers
and displays the sum of all such integers from the list L which end with
the digit 3.
# Function to calculate the sum of integers ending with the digit 3
def sum_ending_with_3(lst):
total = 0
for num in lst:
# Check if the last digit of the number is 3
if num % 10 == 3:
total += num
return total
# Input from the user
L = list(map(int, input("Enter a list of integers (separated by spaces): ").split()))
# Calculate and display the sum
result = sum_ending_with_3(L)
print(f"The sum of integers that end with the digit 3 is: {result}")
OUTPUT
Program4:- Write a program in Python, which input a list L of numbers
and a number to be searched. If the number exists, it is replaced by 0
and if the number does not exist, an appropriate message is displayed.
def replace_number_with_zero(lst, num_to_search):
if num_to_search in lst:
# Replace all occurrences of num_to_search with 0
for i in range(len(lst)):
if lst[i] == num_to_search:
lst[i] = 0
print("Updated list:", lst)
else:
print(f"The number {num_to_search} was not found in the list.")
# Input: list of numbers
L = list(map(int, input("Enter the list of numbers (space-separated): ").split()))
# Input: the number to search for
num = int(input("Enter the number to be searched: "))
# Call the function to replace or show message
replace_number_with_zero(L, num)
OUTPUT
Program5:- Write a Python program, which takes a dictionary Student
as input, the dictionary Student contains Name:(Phy,Chem,Math) as
key:value pairs, program should display the average marks of all
students present in the dictionary.
def calculate_average_marks(student_dict):
for name, marks in student_dict.items():
# Calculate the average of Physics, Chemistry, and Math marks
average_marks = sum(marks) / len(marks)
print(f"Average marks of {name}: {average_marks:.2f}")
# Input: Dictionary of students with their marks in Physics, Chemistry, and Math
student_dict = {}
# Number of students to be entered
n = int(input("Enter the number of students: "))
for _ in range(n):
name = input("Enter student's name: ")
phy = float(input(f"Enter {name}'s marks in Physics: "))
chem = float(input(f"Enter {name}'s marks in Chemistry: "))
math = float(input(f"Enter {name}'s marks in Mathematics: "))
# Adding the student's data to the dictionary
student_dict[name] = [phy, chem, math]
# Display average marks of each student
calculate_average_marks(student_dict)
OUTPUT
Program6:- Write a Python program to read a text file “[Link]” and
print the total number of vowels and consonants separately present in
the text file.
def count_vowels_consonants(filename):
# Initialize vowel and consonant counters
vowels = "aeiouAEIOU"
consonants = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
vowel_count = 0
consonant_count = 0
try:
# Open the file
with open(filename, 'r') as file:
# Read the file content
content = [Link]()
# Loop through each character in the content
for char in content:
if char in vowels:
vowel_count += 1
elif char in consonants:
consonant_count += 1
# Print the counts
print(f"Total vowels: {vowel_count}")
print(f"Total consonants: {consonant_count}")
except FileNotFoundError:
print(f"Error: The file {filename} does not exist.")
# Call the function with the filename '[Link]'
filename = "[Link]"
count_vowels_consonants(filename)
OUTPUT
Program7:- Write a Python program to read a text file “[Link]” and
print the words starting with ‘O’ (Lower/Upper both cases) in reverse
order. The rest of the content is displayed normally.
def process_file(filename):
try:
# Open the file for reading
with open(filename, 'r') as file:
content = [Link]()
# Split the content into words
words = [Link]()
# List to hold words starting with 'O' or 'o'
o_words = [word for word in words if [Link]().startswith('o')]
# Reverse the list of words starting with 'O'
o_words.reverse()
# List to hold the result (with o-words reversed)
result = []
o_index = 0 # Index to track reversed O-words
# Iterate over the original words and build the result
for word in words:
if [Link]().startswith('o') and o_index < len(o_words):
[Link](o_words[o_index])
o_index += 1
else:
[Link](word)
# Join the result into a single string and print
print(' '.join(result))
except FileNotFoundError:
print(f"Error: The file {filename} does not exist.")
# File name
filename = "[Link]"
process_file(filename)
OUTPUT
Program8:-Write a Python program which reads the contents of a text
file "[Link]" and displays the content of the file with every
occurrence of the word 'he' replaced by 'she'.
def replace_he_with_she(filename):
try:
# Open the file to read its contents
with open(filename, 'r') as file:
content = [Link]()
# Replace occurrences of the word 'he' with 'she' (case-sensitive)
modified_content = [Link](' he ', ' she ')
# Special cases: Handle 'he.' and 'he,' as part of punctuation
modified_content = modified_content.replace(' he.', ' she.')
modified_content = modified_content.replace(' he,', ' she,')
modified_content = modified_content.replace(' he!', ' she!')
modified_content = modified_content.replace(' he?', ' she?')
# Print the modified content (or write back to the file if needed)
print(modified_content)
except FileNotFoundError:
print(f"Error: The file {filename} does not exist.")
# File name
filename = "[Link]"
replace_he_with_she(filename)
OUTPUT
Program9:- Write a Python program to count and display the number of
lines starting with ‘A’ (Lower/Upper both cases) present in the text file
“[Link]”.
def count_lines_starting_with_a(filename):
count = 0
# Open the file in read mode
with open(filename, 'r') as file:
# Loop through each line in the file
for line in file:
# Check if the line starts with 'A' or 'a', considering case-insensitivity
if [Link]().lower().startswith('a'):
count += 1
return count
# Specify the filename
filename = "[Link]"
# Get the count of lines starting with 'A' (case-insensitive)
count = count_lines_starting_with_a(filename)
# Display the result
print(f"The number of lines starting with 'A' (case-insensitive) is: {count}")
OUTPUT
Program10:- Write a Python program to count and display the number of
lines that have exactly 5 words in it present in the text file “[Link]”.
def count_lines_with_five_words(filename):
count = 0
# Open the file in read mode
with open(filename, 'r') as file:
# Loop through each line in the file
for line in file:
# Split the line into words and count the words (ignores extra spaces)
words = [Link]()
# Check if the line has exactly 5 words
if len(words) == 5:
count += 1
return count
# Specify the filename
filename = "[Link]"
# Get the count of lines with exactly 5 words
count = count_lines_with_five_words(filename)
# Display the result
print(f"The number of lines with exactly 5 words is: {count}")
OUTPUT
Program11:- Create a binary file “[Link]” with the name and
rollnumber. Search for a given roll number and display the name, if not
found displayappropriate message.
import struct
# Define the structure for each student record
# Name is a string of 50 characters, Roll Number is an integer
student_format = '50s i' # 50 characters (string), 1 integer (roll number)
# Step 1: Create the binary file with student data
def create_student_file(filename):
with open(filename, 'wb') as file:
# Sample student data (name, roll number)
students = [
("Alice", 101),
("Bob", 102),
("Charlie", 103),
("David", 104),
("Eva", 105)
]
# Write each student record to the binary file
for name, roll_number in students:
# Encode the name as bytes and ensure it is 50 characters long
name_encoded = [Link]('utf-8')
name_padded = name_encoded.ljust(50, b'\0') # Padding with null bytes to
make it 50 bytes
# Pack the student record into binary format
student_data = [Link](student_format, name_padded, roll_number)
[Link](student_data)
# Step 2: Search for a student by roll number
def search_student_by_roll_number(filename, search_roll_number):
with open(filename, 'rb') as file:
while True:
# Read each record (each student is 54 bytes: 50 bytes for name + 4 bytes
for roll number)
student_data = [Link]([Link](student_format))
if not student_data:
break # End of file
# Unpack the student data
name, roll_number = [Link](student_format, student_data)
name = [Link]('utf-8').strip('\0') # Decode the name and remove null
bytes
# Check if the roll number matches
if roll_number == search_roll_number:
print(f"Student found: Name: {name}, Roll Number: {roll_number}")
return
# If not found
print(f"Student with roll number {search_roll_number} not found.")
# Main execution
filename = "[Link]"
create_student_file(filename) # Create the file and populate with data
# Example: Search for a given roll number
search_roll_number = int(input("Enter the roll number to search: "))
search_student_by_roll_number(filename, search_roll_number)
OUTPUT
Program12:- Create a binary file “[Link]” with roll number, name and
marks. Input a roll number and update details. Create a binary file with
roll number, name and marks. Input a roll number and update details.
import struct
# Define the structure of a student record
# 'i' is for roll number (int), '50s' for name (string of 50 characters), 'f' for marks (float)
student_format = 'i 50s f' # Roll number (int), Name (50 char string), Marks (float)
# Step 1: Create the binary file and populate it with student data
def create_student_file(filename):
with open(filename, 'wb') as file:
# Sample student data (roll_number, name, marks)
students = [
(101, "Alice", 85.5),
(102, "Bob", 90.0),
(103, "Charlie", 78.0),
(104, "David", 92.5),
(105, "Eva", 88.5)
]
# Write each student record to the binary file
for roll_number, name, marks in students:
# Encode name to bytes and ensure it's 50 characters long
name_encoded = [Link]('utf-8')
name_padded = name_encoded.ljust(50, b'\0') # Padding with null bytes to
make it 50 bytes
# Pack the student record into binary format
student_data = [Link](student_format, roll_number, name_padded,
marks)
[Link](student_data)
# Step 2: Search for a student by roll number and update their details
def update_student_details(filename, search_roll_number, new_name, new_marks):
updated = False
# Read the entire file, then update the specific record
with open(filename, 'r+b') as file: # 'r+b' allows reading and writing in binary mode
while True:
# Read one student record at a time (56 bytes: 4 for roll number, 50 for
name, 4 for marks)
student_data = [Link]([Link](student_format))
if not student_data:
break # End of file
# Unpack the student record
roll_number, name, marks = [Link](student_format, student_data)
name = [Link]('utf-8').strip('\0') # Remove padding null bytes from the
name
# Check if the roll number matches the search roll number
if roll_number == search_roll_number:
# If found, update the details
print(f"Student found: {name} with roll number {roll_number} and marks
{marks}")
# Encode new name and pad it to 50 characters
new_name_encoded = new_name.encode('utf-8')
new_name_padded = new_name_encoded.ljust(50, b'\0')
# Pack the updated student data
updated_student_data = [Link](student_format, roll_number,
new_name_padded, new_marks)
# Move the file pointer to the beginning of the current record
[Link](-[Link](student_format), 1) # Move file pointer back to
the current position
[Link](updated_student_data) # Write the updated record to the file
updated = True
break # Exit after updating the first matching student
if not updated:
print(f"Student with roll number {search_roll_number} not found.")
else:
print(f"Student details updated successfully.")
# Main execution
filename = "[Link]"
create_student_file(filename) # Create the file and populate it with student data
# Input: Roll number to search and update details
search_roll_number = int(input("Enter the roll number to update: "))
new_name = input("Enter the new name: ")
new_marks = float(input("Enter the new marks: "))
# Update the student details
update_student_details(filename, search_roll_number, new_name, new_marks)
OUTPUT
Program13:- Write a program using the following functions :
A binary file “[Link]” has structure [BookNo, Book_Name, Author,
Price].
1. Write a user defined function CreateFile() to input data for a record
and add to [Link] .
2. Write a function CountRec(Author) in Python which accepts the
Author name as parameter and count and return number of books
by the given
Author are stored in the binary file “[Link]”
import struct
# Define the structure of a book record
# 'i' for BookNo (integer), '50s' for Book_Name (string of 50 characters),
# '50s' for Author (string of 50 characters), 'f' for Price (float)
book_format = 'i 50s 50s f'
# Step 1: CreateFile function to input book data and add it to "[Link]"
def CreateFile(filename):
with open(filename, 'ab') as file: # 'ab' for append binary mode
while True:
# Get user input for each book record
try:
book_no = int(input("Enter Book Number (integer): "))
book_name = input("Enter Book Name: ")
author = input("Enter Author Name: ")
price = float(input("Enter Book Price: "))
except ValueError:
print("Invalid input. Please enter the correct data types.")
continue
# Encode the book name and author to bytes and pad them to 50 characters
each
book_name_encoded = book_name.encode('utf-8')
book_name_padded = book_name_encoded.ljust(50, b'\0') # Padding with
null bytes
author_encoded = [Link]('utf-8')
author_padded = author_encoded.ljust(50, b'\0') # Padding with null bytes
# Pack the book record into binary format
book_data = [Link](book_format, book_no, book_name_padded,
author_padded, price)
# Write the packed data to the binary file
[Link](book_data)
# Ask if the user wants to add more records
more = input("Do you want to add another book? (y/n): ").lower()
if more != 'y':
break
# Step 2: CountRec function to count the number of books by a given author
def CountRec(filename, author_name):
count = 0
with open(filename, 'rb') as file: # Open file in binary read mode
while True:
# Read one record (106 bytes: 4 for BookNo, 50 for Book_Name, 50 for
Author, 4 for Price)
book_data = [Link]([Link](book_format))
if not book_data:
break # End of file
# Unpack the book data
book_no, book_name, author, price = [Link](book_format, book_data)
# Decode the name and author, removing padding
book_name = book_name.decode('utf-8').strip('\0')
author = [Link]('utf-8').strip('\0')
# Check if the author matches the given author name
if [Link]() == author_name.lower():
count += 1
return count
# Main execution
filename = "[Link]"
# Create the binary file and add records to it
CreateFile(filename)
# Input: Author name to count the books
author_to_search = input("Enter the Author's name to count their books: ")
# Count the books by the given author
book_count = CountRec(filename, author_to_search)
# Display the result
print(f"Number of books by {author_to_search}: {book_count}")
OUTPUT
Program14:- Write a program to perform read and write operation onto a
“[Link]” file having fields as roll number, name, stream and
percentage.
import csv
# Function to write student data into the CSV file
def write_to_csv(filename):
# Open the file in write mode (will overwrite the file if it exists)
with open(filename, mode='w', newline='') as file:
writer = [Link](file)
# Write the header (column names)
[Link](['Roll Number', 'Name', 'Stream', 'Percentage'])
while True:
# Take student details as input
try:
roll_number = int(input("Enter Roll Number: "))
name = input("Enter Name: ")
stream = input("Enter Stream (e.g., Science, Arts, Commerce): ")
percentage = float(input("Enter Percentage: "))
except ValueError:
print("Invalid input. Please enter the correct data types.")
continue
# Write the student's data into the CSV file
[Link]([roll_number, name, stream, percentage])
# Ask if the user wants to add another student
more = input("Do you want to add another student? (y/n): ").lower()
if more != 'y':
break
# Function to read and display the data from the CSV file
def read_from_csv(filename):
# Open the file in read mode
with open(filename, mode='r') as file:
reader = [Link](file)
# Read and display all the rows
print("\nStudent Data from CSV file:")
for row in reader:
print(row)
# Main execution
filename = '[Link]'
# Write student data to the CSV file
write_to_csv(filename)
# Read and display the data from the CSV file
read_from_csv(filename)
OUTPUT
Program15:- Write a program to copy the data from “[Link]” to
“[Link]”.
import csv
# Function to copy data from '[Link]' to '[Link]'
def copy_csv_data(source_filename, destination_filename):
# Open the source CSV file in read mode
with open(source_filename, mode='r') as source_file:
reader = [Link](source_file)
# Open the destination CSV file in write mode
with open(destination_filename, mode='w', newline='') as dest_file:
writer = [Link](dest_file)
# Copy each row from the source to the destination
for row in reader:
[Link](row)
# Main execution
source_filename = '[Link]'
destination_filename = '[Link]'
# Call the function to copy data
copy_csv_data(source_filename, destination_filename)
print(f"Data has been copied from {source_filename} to {destination_filename}")
OUTPUT
Program16:- Write a program to create a library on your name in python
and import it in a program.
# [Link] - A simple library system library
# Function to add a book to the library
def add_book(book_list, title, author, year):
book_list.append({"Title": title, "Author": author, "Year": year})
print(f"Book '{title}' by {author} added successfully!")
# Function to search for a book by title
def search_book(book_list, title):
for book in book_list:
if book["Title"].lower() == [Link]():
return book
return None
# Function to list all books
def list_books(book_list):
if not book_list:
print("No books available in the library.")
return
print("Books in the library:")
for idx, book in enumerate(book_list, 1):
print(f"{idx}. {book['Title']} by {book['Author']} ({book['Year']})")
# Function to remove a book by title
def remove_book(book_list, title):
for book in book_list:
if book["Title"].lower() == [Link]():
book_list.remove(book)
print(f"Book '{title}' removed from the library!")
return
print(f"Book '{title}' not found.")
OUTPUT
Program:-17Write a program which adds any random five even numbers
in a list that falls between the highest and the lowest number. Both
highest and lowest numbers are accepted from the user.
import random
# Function to generate a list of random even numbers
def generate_random_evens(lowest, highest, count=5):
# Adjust the lowest value to the next even number if it's odd
if lowest % 2 != 0:
lowest += 1
# Adjust the highest value to the previous even number if it's odd
if highest % 2 != 0:
highest -= 1
# Generate a list of `count` random even numbers within the range [lowest,
highest]
even_numbers = []
while len(even_numbers) < count:
num = [Link](lowest, highest)
if num % 2 == 0:
even_numbers.append(num)
return even_numbers
# Main execution
def main():
# Accept the lowest and highest numbers from the user
try:
lowest = int(input("Enter the lowest number: "))
highest = int(input("Enter the highest number: "))
# Ensure the lowest number is less than the highest number
if lowest >= highest:
print("The lowest number must be less than the highest number. Please try
again.")
return
# Generate 5 random even numbers between the lowest and highest values
even_numbers = generate_random_evens(lowest, highest)
# Display the result
print("The list of 5 random even numbers:", even_numbers)
except ValueError:
print("Invalid input! Please enter valid integers.")
# Run the main function
main()
OUTPUT
Program18:- A list contains following record of customer:
[Customer_name, Room_Type]
Write a complete program using the following user defined function to
perform given operations on the stack named 'Hotel':
(a) Push_Cust(): To push customers' names of those who are staying in
'Delux' Room Type.
(b) Pop_Cust(): To pop the names of customers from the stack and
display them. Also display "Underflow" when there are no customers in
the stack.
class Hotel:
def __init__(self):
[Link] = []
# Function to push customer names into the stack who are staying in 'Delux'
Room Type
def Push_Cust(self, customers):
for customer in customers:
name, room_type = customer
if room_type == 'Delux':
[Link](name)
print(f"Customer '{name}' with 'Delux' Room Type added to the stack.")
# Function to pop customer names from the stack and display them
def Pop_Cust(self):
if len([Link]) == 0:
print("Underflow: No customers in the stack.")
else:
popped_customer = [Link]()
print(f"Customer '{popped_customer}' has been removed from the stack.")
# Main execution
def main():
# Sample customer records: [Customer_name, Room_Type]
customers = [
["Alice", "Delux"],
["Bob", "Standard"],
["Charlie", "Delux"],
["David", "Standard"],
["Eve", "Delux"]
]
# Create the hotel stack
hotel_stack = Hotel()
# Push customers who are staying in 'Delux' Room Type onto the stack
hotel_stack.Push_Cust(customers)
# Pop customers from the stack
hotel_stack.Pop_Cust() # Pops one customer
hotel_stack.Pop_Cust() # Pops another customer
hotel_stack.Pop_Cust() # Pops another customer
hotel_stack.Pop_Cust() # Pops another customer
hotel_stack.Pop_Cust() # Pops the last customer
hotel_stack.Pop_Cust() # Underflow case (No customers left)
# Run the main function
main()
OUTPUT
Program19:- A school stores records of Class XII students using a list
that contains multiple lists as its elements. The structure of each such
element is [Student_Name, Marks, MainSubject].
Crate a complete program using the user-defined functions to perform
the operations as mentioned below:
(a) Push_student(): To push the Student_Name and Marks of all those
students, who have Science as MainSubject, into a Stack StudentInfo
(b) Pop_student(): To delete all items (one at a time) from the stack
StudentInfo in LIFO order and display them. Also display "Empty Stack"
when there are no items remaining in the stack.
class School:
def __init__(self):
# Initialize the stack as an empty list
[Link] = []
# Function to push students with Science as MainSubject into the stack
def Push_student(self, student_records):
for record in student_records:
name, marks, main_subject = record
if main_subject == 'Science':
[Link]([name, marks])
print(f"Student '{name}' with marks {marks} added to the stack.")
# Function to pop all student records from the stack and display them
def Pop_student(self):
if len([Link]) == 0:
print("Empty Stack: No students to pop.")
else:
while len([Link]) > 0:
student = [Link]()
print(f"Student '{student[0]}' with marks {student[1]} removed from the
stack.")
# Main execution
def main():
# Sample student records: [Student_Name, Marks, MainSubject]
students = [
["Alice", 85, "Science"],
["Bob", 78, "Commerce"],
["Charlie", 92, "Science"],
["David", 88, "Arts"],
["Eve", 95, "Science"]
]
# Create the School object to manage student records
school = School()
# Push students with Science as MainSubject into the stack
school.Push_student(students)
# Pop all student records from the stack
school.Pop_student()
# Try popping again to demonstrate the Empty Stack message
school.Pop_student()
# Run the main function
main()
OUTPUT
Program20:- Write a program to connect Python with MySQL using
database connectivity and perform the following operations on data
in Database: A) Create, B) Insert, C) Fetch, D) Update and E) Delete
the data.
import [Link]
from [Link] import Error
# Function to connect to MySQL
def create_connection():
try:
connection = [Link](
host='localhost', # MySQL server address (e.g., localhost)
user='root', # MySQL username
password='password', # MySQL password (replace with your actual
password)
database='school_db' # Database name
)
if connection.is_connected():
print("Connection to MySQL database established.")
return connection
except Error as e:
print(f"Error: {e}")
return None
# A) Create Table
def create_table(connection):
cursor = [Link]()
[Link]("""
CREATE TABLE IF NOT EXISTS students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
student_name VARCHAR(100) NOT NULL,
student_age INT NOT NULL,
student_grade VARCHAR(10) NOT NULL
)
""")
[Link]()
print("Table 'students' created successfully.")
# B) Insert Data into the Table
def insert_student(connection, name, age, grade):
cursor = [Link]()
query = "INSERT INTO students (student_name, student_age,
student_grade) VALUES (%s, %s, %s)"
[Link](query, (name, age, grade))
[Link]()
print(f"Student {name} inserted successfully.")
# C) Fetch Data from the Table
def fetch_students(connection):
cursor = [Link]()
query = "SELECT * FROM students"
[Link](query)
records = [Link]()
print("Students Data:")
for row in records:
print(f"ID: {row[0]}, Name: {row[1]}, Age: {row[2]}, Grade: {row[3]}")
# D) Update Data in the Table
def update_student_grade(connection, student_id, new_grade):
cursor = [Link]()
query = "UPDATE students SET student_grade = %s WHERE student_id =
%s"
[Link](query, (new_grade, student_id))
[Link]()
print(f"Student ID {student_id} updated with new grade {new_grade}.")
# E) Delete Data from the Table
def delete_student(connection, student_id):
cursor = [Link]()
query = "DELETE FROM students WHERE student_id = %s"
[Link](query, (student_id,))
[Link]()
print(f"Student ID {student_id} deleted successfully.")
# Main Execution Function
def main():
# Step 1: Establish MySQL connection
connection = create_connection()
if connection is None:
return
# Step 2: Create Table
create_table(connection)
# Step 3: Insert sample data
insert_student(connection, 'Alice', 20, 'A')
insert_student(connection, 'Bob', 21, 'B')
insert_student(connection, 'Charlie', 22, 'A')
# Step 4: Fetch and display all students
fetch_students(connection)
# Step 5: Update a student's grade
update_student_grade(connection, 1, 'A+') # Update Alice's grade
# Step 6: Fetch and display all students again to see the update
fetch_students(connection)
# Step 7: Delete a student record
delete_student(connection, 2) # Delete Bob's record
# Step 8: Fetch and display remaining students
fetch_students(connection)
# Close the connection
[Link]()
# Run the program
if __name__ == "__main__":
main()
OUTPUT