0% found this document useful (0 votes)
7 views22 pages

Class XII Set 1-Set 4 Practical 2025-26

The document contains multiple Python programs for managing different types of data using binary files, including bank accounts, student records, airline bookings, and grocery store items. Each program features a menu-driven interface that allows users to perform operations such as adding, displaying, updating, searching, and deleting records. Additionally, SQL queries are provided for various database operations related to bookings, teachers, and books.

Uploaded by

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

Class XII Set 1-Set 4 Practical 2025-26

The document contains multiple Python programs for managing different types of data using binary files, including bank accounts, student records, airline bookings, and grocery store items. Each program features a menu-driven interface that allows users to perform operations such as adding, displaying, updating, searching, and deleting records. Additionally, SQL queries are provided for various database operations related to bookings, teachers, and books.

Uploaded by

user-486271
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Class XII Set 1

Q1. Write a menu-driven program to perform all the basic operations using a dictionary on a
bank_accounts.dat binary file. The operations include:

1. Add Account
2. Display Accounts
3. Update the Balance for an Account
4. Search Account based on Account_Number
5. Delete Account based on Account_Number
6. Exit

The structure of the file content is: [Account_Number, Account_Holder_Name, Account_Type,


Balance, Branch].
Write a Python program to implement the above functionality.

Ans1.
import pickle

# Function to add a new account


def add_account(filename):
account = {}
with open(filename, 'ab') as file:
account['Account_Number'] = input("Enter Account Number: ")
account['Account_Holder_Name'] = input("Enter Account Holder Name: ")
account['Account_Type'] = input("Enter Account Type (Savings/Current): ")
account['Balance'] = float(input("Enter Balance: "))
account['Branch'] = input("Enter Branch: ")
pickle.dump(account, file)
print("Account added successfully!")

# Function to display all accounts


def display_accounts(filename):
try:
with open(filename, 'rb') as file:
print("\nAccounts in the file:")
while True:
account = pickle.load(file)
print(account)
except EOFError:
pass
except FileNotFoundError:
print("File not found! No accounts to display.")

# Function to update balance for an account


def update_balance(filename):
updated = False
account_number = input("Enter Account Number to update balance: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
account = pickle.load(file)
if account['Account_Number'] == account_number:
print(f"Current Balance: {account['Balance']}")
account['Balance'] = float(input("Enter new Balance: "))
print("Balance updated successfully!")
updated = True
pickle.dump(account, temp)
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if updated:
os.rename(temp_file, filename)
else:
print("Account not found!")

# Function to search an account


def search_account(filename):
account_number = input("Enter Account Number to search: ")
found = False
try:
with open(filename, 'rb') as file:
while True:
account = pickle.load(file)
if account['Account_Number'] == account_number:
print("Account Found:", account)
found = True
break
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if not found:
print("Account not found!")
# Function to delete an account
def delete_account(filename):
deleted = False
account_number = input("Enter Account Number to delete: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
account = pickle.load(file)
if account['Account_Number'] != account_number:
pickle.dump(account, temp)
else:
print("Account deleted successfully!")
deleted = True
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if deleted:
os.rename(temp_file, filename)
else:
print("Account not found!")

# Main menu
def main():
filename = 'bank_accounts.dat'
while True:
print("\nMenu:")
print("1. Add Account")
print("2. Display Accounts")
print("3. Update Balance")
print("4. Search Account")
print("5. Delete Account")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
add_account(filename)
elif choice == '2':
display_accounts(filename)
elif choice == '3':
update_balance(filename)
elif choice == '4':
search_account(filename)
elif choice == '5':
delete_account(filename)
elif choice == '6':
print("Exiting program...")
break
else:
print("Invalid choice! Please try again.")

# Run the program


if __name__ == "__main__":
main()
Question 2 : Queries
1. SELECT Destination, SUM(Fare) AS Total_Fare FROM Indigo_Booking GROUP BY
Destination;
2. UPDATE Indigo_Booking SET Fare = Fare * 1.15 WHERE Source = 'Delhi';
3. SELECT p.P_ID, p.PName, p.Age, p.Mobile, p.Frequent_Flyer FROM Passengers p
JOIN Indigo_Booking b ON p.P_ID = b.P_ID WHERE p.Gender = 'Male' AND p.Age
BETWEEN 40 AND 50
AND p.Frequent_Flyer = 'Yes';
4. SELECT p.PName, b.Destination, b.Fare FROM Passengers p JOIN Indigo_Booking b ON
p.P_ID = b.P_ID ORDER BY b.Fare DESC;

Set 2 Class : XII


Q1: Write a menu-driven program to perform all the basic operations using a dictionary on a
Students.dat binary file. The operations include:

Add Record
Display Records
Update Marks for a Record
Search Record based on Roll_No
Delete Record based on Roll_No
Exit
The structure of the file content is: [Roll_No, Name, Class, Marks].

Write a Python program to implement the above functionality.


Q1.
import pickle
import os
# Function to add a new record
def add_record(filename):
student = {}
with open(filename, 'ab') as file:
student['Roll_No'] = input("Enter Roll Number: ")
student['Name'] = input("Enter Student Name: ")
student['Class'] = input("Enter Class: ")
student['Marks'] = float(input("Enter Marks: "))
pickle.dump(student, file)
print("Record added successfully!")

# Function to display all records


def display_records(filename):
try:
with open(filename, 'rb') as file:
print("\nStudents in the file:")
while True:
student = pickle.load(file)
print(student)
except EOFError:
pass
except FileNotFoundError:
print("File not found! No records to display.")

# Function to update marks for a record


def update_marks(filename):
updated = False
roll_no = input("Enter Roll Number to update Marks: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
student = pickle.load(file)
if student['Roll_No'] == roll_no:
print(f"Current Marks: {student['Marks']}")
student['Marks'] = float(input("Enter new Marks: "))
print("Marks updated successfully!")
updated = True
pickle.dump(student, temp)
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if updated:
os.rename(temp_file, filename)
else:
print("Student not found!")

# Function to search for a record


def search_record(filename):
roll_no = input("Enter Roll Number to search: ")
found = False
try:
with open(filename, 'rb') as file:
while True:
student = pickle.load(file)
if student['Roll_No'] == roll_no:
print("Record Found:", student)
found = True
break
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if not found:
print("Record not found!")

# Function to delete a record


def delete_record(filename):
deleted = False
roll_no = input("Enter Roll Number to delete: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
student = pickle.load(file)
if student['Roll_No'] != roll_no:
pickle.dump(student, temp)
else:
print("Record deleted successfully!")
deleted = True
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if deleted:
os.rename(temp_file, filename)
else:
print("Record not found!")

# Main menu
def main():
filename = 'Students.dat'
while True:
print("\nMenu:")
print("1. Add Record")
print("2. Display Records")
print("3. Update Marks")
print("4. Search Record")
print("5. Delete Record")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
add_record(filename)
elif choice == '2':
display_records(filename)
elif choice == '3':
update_marks(filename)
elif choice == '4':
search_record(filename)
elif choice == '5':
delete_record(filename)
elif choice == '6':
print("Exiting program...")
break
else:
print("Invalid choice! Please try again.")

# Run the program


if __name__ == "__main__":
main()
Answer 2 . Queries
1. SELECT * FROM Books WHERE Genre = 'Fiction' AND Available_Copies < 3;
2. SELECT * FROM Issued ORDER BY Fine_Amount DESC;
3. UPDATE Issued SET Fine_Amount = Fine_Amount * 1.2;
4. SELECT b.Book_ID, b.Title, i.Student_Name, i.Due_Date FROM Books b
JOIN Issued i ON b.Book_ID = i.Book_ID;

Set -3 Class XII


Q1: Write a menu-driven program to perform all the basic operations using a dictionary on an
Airline_Booking.dat binary file. The operations include:

Add Booking
Display Bookings
Update Passenger's Seat Number
Search Booking based on Booking_ID
Delete Booking based on Booking_ID
Exit
The structure of the file content is: [Booking_ID, Passenger_Name, Flight_No, Seat_No,
Destination].

Write a Python program to implement the above functionality.


import pickle
import os

# Function to add a new booking


def add_booking(filename):
booking = {}
with open(filename, 'ab') as file:
booking['Booking_ID'] = input("Enter Booking ID: ")
booking['Passenger_Name'] = input("Enter Passenger Name: ")
booking['Flight_No'] = input("Enter Flight Number: ")
booking['Seat_No'] = input("Enter Seat Number: ")
booking['Destination'] = input("Enter Destination: ")
pickle.dump(booking, file)
print("Booking added successfully!")

# Function to display all bookings


def display_bookings(filename):
try:
with open(filename, 'rb') as file:
print("\nBookings in the file:")
while True:
booking = pickle.load(file)
print(booking)
except EOFError:
pass
except FileNotFoundError:
print("File not found! No bookings to display.")

# Function to update the seat number for a booking


def update_seat_number(filename):
updated = False
booking_id = input("Enter Booking ID to update Seat Number: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
booking = pickle.load(file)
if booking['Booking_ID'] == booking_id:
print(f"Current Seat Number: {booking['Seat_No']}")
booking['Seat_No'] = input("Enter new Seat Number: ")
print("Seat Number updated successfully!")
updated = True
pickle.dump(booking, temp)
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if updated:
os.rename(temp_file, filename)
else:
print("Booking not found!")

# Function to search for a booking


def search_booking(filename):
booking_id = input("Enter Booking ID to search: ")
found = False
try:
with open(filename, 'rb') as file:
while True:
booking = pickle.load(file)
if booking['Booking_ID'] == booking_id:
print("Booking Found:", booking)
found = True
break
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if not found:
print("Booking not found!")

# Function to delete a booking


def delete_booking(filename):
deleted = False
booking_id = input("Enter Booking ID to delete: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
booking = pickle.load(file)
if booking['Booking_ID'] != booking_id:
pickle.dump(booking, temp)
else:
print("Booking deleted successfully!")
deleted = True
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if deleted:
os.rename(temp_file, filename)
else:
print("Booking not found!")

# Main menu
def main():
filename = 'Airline_Booking.dat'
while True:
print("\nMenu:")
print("1. Add Booking")
print("2. Display Bookings")
print("3. Update Seat Number")
print("4. Search Booking")
print("5. Delete Booking")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
add_booking(filename)
elif choice == '2':
display_bookings(filename)
elif choice == '3':
update_seat_number(filename)
elif choice == '4':
search_booking(filename)
elif choice == '5':
delete_booking(filename)
elif choice == '6':
print("Exiting program...")
break
else:
print("Invalid choice! Please try again.")

# Run the program


if __name__ == "__main__":
main()
Answer2 Queries
1. SELECT T_Name, Dept_Code, Salary FROM TEACHERS ORDER BY Experience
DESC;
2. SELECT T_Name, Salary FROM TEACHERS WHERE T_Name LIKE 'N%' AND
Salary > 75000;
3. SELECT MAX(Salary) AS Highest_Salary FROM TEACHERS;
4. SELECT d.Dept_Name, t.T_Name FROM DEPARTMENT d JOIN TEACHERS t ON
d.Dept_Code = t.Dept_Code;
Set 4 Question 1
Q1: Write a menu-driven program to perform all the basic operations using a dictionary on a
Grocery_Store.dat binary file for Reliance Store. The operations include:

Add Item
Display All Items
Update the Stock Quantity for an Item
Search Item based on Product_ID
Delete Item based on Product_ID
Exit
The structure of the file content is: [Product_ID, Product_Name, Category, Price_per_Unit,
Stock_Quantity].

Write a Python program to implement the above functionality


import pickle
import os

# Function to add a new item


def add_item(filename):
item = {}
with open(filename, 'ab') as file:
item['Product_ID'] = input("Enter Product ID: ")
item['Product_Name'] = input("Enter Product Name: ")
item['Category'] = input("Enter Category (e.g., Vegetables, Snacks): ")
item['Price_per_Unit'] = float(input("Enter Price per Unit: "))
item['Stock_Quantity'] = int(input("Enter Stock Quantity: "))
pickle.dump(item, file)
print("Item added successfully!")

# Function to display all items


def display_items(filename):
try:
with open(filename, 'rb') as file:
print("\nItems in the store:")
while True:
item = pickle.load(file)
print(item)
except EOFError:
pass
except FileNotFoundError:
print("File not found! No items to display.")

# Function to update stock quantity for an item


def update_stock_quantity(filename):
updated = False
product_id = input("Enter Product ID to update Stock Quantity: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
item = pickle.load(file)
if item['Product_ID'] == product_id:
print(f"Current Stock Quantity: {item['Stock_Quantity']}")
item['Stock_Quantity'] = int(input("Enter new Stock Quantity: "))
print("Stock Quantity updated successfully!")
updated = True
pickle.dump(item, temp)
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if updated:
os.rename(temp_file, filename)
else:
print("Product not found!")

# Function to search for an item


def search_item(filename):
product_id = input("Enter Product ID to search: ")
found = False
try:
with open(filename, 'rb') as file:
while True:
item = pickle.load(file)
if item['Product_ID'] == product_id:
print("Item Found:", item)
found = True
break
except EOFError:
pass
except FileNotFoundError:
print("File not found!")
if not found:
print("Item not found!")

# Function to delete an item


def delete_item(filename):
deleted = False
product_id = input("Enter Product ID to delete: ")
temp_file = 'temp.dat'
try:
with open(filename, 'rb') as file, open(temp_file, 'wb') as temp:
while True:
item = pickle.load(file)
if item['Product_ID'] != product_id:
pickle.dump(item, temp)
else:
print("Item deleted successfully!")
deleted = True
except EOFError:
pass
except FileNotFoundError:
print("File not found!")

if deleted:
os.rename(temp_file, filename)
else:
print("Item not found!")
# Main menu
def main():
filename = 'Grocery_Store.dat'
while True:
print("\nMenu:")
print("1. Add Item")
print("2. Display All Items")
print("3. Update Stock Quantity")
print("4. Search Item")
print("5. Delete Item")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
add_item(filename)
elif choice == '2':
display_items(filename)
elif choice == '3':
update_stock_quantity(filename)
elif choice == '4':
search_item(filename)
elif choice == '5':
delete_item(filename)
elif choice == '6':
print("Exiting program...")
break
else:
print("Invalid choice! Please try again.")
# Run the program
if __name__ == "__main__":
main()
Answer 2.Queries
1. SELECT * FROM PRODUCTS ORDER BY PROD_NAME ASC;
2. SELECT * FROM PRODUCTS WHERE CATEGORY = 'Smartphones' AND PRICE >
100000;
3. SELECT s.CUSTOMER_NAME, p.PROD_NAME FROM SALE s JOIN PRODUCTS
p ON s.PROD_ID = p.PROD_ID WHERE s.CUSTOMER_NAME IS NOT NULL;
4. SELECT * FROM PRODUCTS WHERE PROD_ID NOT IN (SELECT PROD_ID
FROM SALE WHERE PROD_ID IS NOT NULL);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy