BINARY
BINARY
import pickle
def Write():
f = open("BinaryData.dat", "wb")
while True:
rno = int(input("Roll No: "))
name = input("Name: ")
marks = int(input("Marks: "))
data = [rno, name, marks]
pickle.dump(data,f)
ch = input("Do you want to add more records?
(y/n): ")
if ch in 'nN':
break
f.close()
def Read():
f = open("BinaryData.dat", "rb")
try:
while True:
data = pickle.load(f)
print(data)
except EOFError:
f.close()
def Search():
f = open("BinaryData.dat", "rb")
r = int(input("Enter roll number whose record is
to be searched: "))
try:
while True:
data = pickle.load(f)
if data[0] == r:
print(data)
except EOFError:
f.close()
def Update():
f = open("BinaryData.dat", "rb")
r = int(input("Enter roll number whose marks is to
be updated: "))
L =[]
try:
while True:
data = pickle.load(f)
if data[0] == r:
data[2] = int(input("Enter updated
marks: "))
L.append(data)
except EOFError:
f.close()
f = open("BinaryData.dat", "wb")
pickle.dump(L, f)
f.close()
Write()
Read()
Search()
Update()
import pickle
def WRITEREC():
f = open("Plants.dat", "wb")
while True:
ID = int(input("Plant Id: "))
Name = input("Name: ")
Price = int(input("Price: "))
Data = [ID, Name, Price]
pickle.dump(Data,f)
ch = input("More? (y/n): ")
if ch in 'nN':
break
f.close()
def SHOWHIGH():
f = open("Plants.dat", "rb")
try:
while True:
data = pickle.load(f)
If data[2]>500:
print(data)
except EOFError:
f.close()
import pickle
def CreateFile():
f = open("Book.dat", "wb")
while True:
BookNo = int(input("Book No.: "))
BookName = input("Book Name: ")
Author = input("Author: ")
Price = int(input(“Price”: )
Data = [BookNo, BookName, Author, Price]
pickle.dump(Data,f)
ch = input("More? (y/n): ")
if ch in 'nN':
break
f.close()
def CountRec():
f = open(Book.dat", "rb")
Author = input("Author : ")
count = 0
try:
while True:
data = pickle.load(f)
if data[2] == Author:
count += 1
except EOFError:
f.close()
return count
def CreateFile():
f = open("Cinema.dat", "wb")
while True:
MNo = int(input("Movie No.: "))
MName = input("Movie Name: ")
Mtype = input("Movie Type: ")
Data = [MNo, MName, Mtype]
pickle.dump(Data,f)
ch = input("More? (y/n): ")
if ch in 'nN':
break
f.close()
def searh_copy():
f = open(“Cinema.dat", "rb")
try:
while True:
data = pickle.load(f)
if data[2] == “Comedy”:
print(data)
except EOFError:
f.close()
import pickle
def CreateFile():
f = open("Cinema.dat", "wb")
while True:
MNo = int(input("Movie No.: "))
MName = input("Movie Name: ")
Mtype = input("Movie Type: ")
Data = [MNo, MName, Mtype]
pickle.dump(Data,f)
ch = input("More? (y/n): ")
if ch in 'nN':
break
f.close()
def searh_copy():
f = open(“Cinema.dat", "rb")
f1 = open(“Movie.dat”, “wb”)
try:
while True:
data = pickle.load(f)
if data[2] == “Comedy”:
pickle.dump(data, f1)
except EOFError:
f.close()