-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathbinary.py
46 lines (44 loc) · 894 Bytes
/
binary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#WAP to define read ,search,write
import pickle
def write():
f=open("b.dat","wb")
d=[]
while True:
r=int(input("enter roll:"))
n=input("Enter name:")
m=int(input("enter marks:"))
l=[r,n,m]
d.append(l)
ch=input("Do you want to add more?Y/n")
if ch in 'Nn':
break
pickle.dump(d,f)
f.close()
def read():
f=open("b.dat","rb")
r=pickle.load(f)
for i in r:
k=i[0]
n=i[1]
m=i[2]
print(k,n,m)
f.close()
def search():
f=open("b.dat","rb")
x=pickle.load(f)
r=int(input("Enter roll that is to be searched"))
c=0
for i in x:
if i[0]==r:
j=i[0]
n=i[1]
m=i[2]
print(j,n,m)
c=c+1
break
if c==0:
print("roll not found")
f.close()
write()
read()
search()