0% found this document useful (0 votes)
10 views5 pages

Bhavya Set1

Uploaded by

xacako9695
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)
10 views5 pages

Bhavya Set1

Uploaded by

xacako9695
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/ 5

Practical class 12

Code-

import pickle

def create():

f=open("shoes.dat","ab")

opt="y"

while opt=="y":

s_id=int(input("enter s_id"))

name=input("enter name")

brand=input("enter brand")

type_=input("enter type")

price=int(input("enter price"))

L=[s_id,name,brand,type_,price]

pickle.dump(L,f)

opt=input("do you wnat to add more records(y/n)")

f.close()

def search():

f=open("shoes.dat","rb")

no=int(input("enter the s_id"))

found=0

try:

while True:

s=pickle.load(f)

if s[0]==no:

print("searched droll no. is found",s)

found=1

break

except:

f.close()
if found==0:

print("searched roll no. is not found")

def display():

try:

with open('shoes.dat', 'rb') as file:

while True:

shoe = pickle.load(file)

print(shoe)

break

print("No records found. File not found.")

create()

search()

def menu():

while True:

print("\nMenu:")

print("1. Add record")

print("2. display")

print("3. Search record")

print("4. Exit")

choice = input("Enter your choice: ")

if choice == '1':

create()

elif choice == '2':

display()

elif choice == '3':

search()
elif choice == '4':

print("Exiting program...")

break

else:

print("Invalid choice! Please try again.")

menu()

output-

You might also like