Class XII Set 1-Set 4 Practical 2025-26
Class XII Set 1-Set 4 Practical 2025-26
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
Ans1.
import pickle
if updated:
os.rename(temp_file, filename)
else:
print("Account 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.")
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].
if updated:
os.rename(temp_file, filename)
else:
print("Student not found!")
if not found:
print("Record 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.")
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].
if updated:
os.rename(temp_file, filename)
else:
print("Booking not found!")
if not found:
print("Booking 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.")
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].
if updated:
os.rename(temp_file, filename)
else:
print("Product 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);