-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbinary mock drill 12th.py
166 lines (135 loc) · 3.93 KB
/
binary mock drill 12th.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import pickle
import os
def add_mobile():
global l
model = int(input("Enter Mobile Model :"))
company = input("Enter Mobile Company :")
price = int(input("Enter Mobile Price :"))
l = [model, company, price]
fobj = open("mobile.dat", "ab")
fwb = pickle.dump(l, fobj)
def show_all():
if os.path.isfile("Mobile.dat"):
fobj = open("mobile.dat", "rb")
while True:
try:
frb = pickle.load(fobj)
print(frb)
except:
fobj.close()
break
else:
print("File not exists")
def show_model(modelno):
fobj=open("Mobile.dat", "rb")
while True:
try:
frb=pickle.load(fobj)
if frb[0]==n1:
print(frb[0], frb[1], frb[2])
except:
fobj.close()
break
def delete_mobile(modelno):
if os.path.isfile("Mobile.dat"):
fobj=open("Mobile.dat", "rb")
temp=open("temp.dat", "wb")
found=0
while True:
try:
frb1=pickle.load(fobj)
if frb1[0] != n2:
frb2=pickle.dump(frb1,temp)
else:
found =1
except:
break
fobj.close()
temp.close()
os.remove("Mobile.dat")
os.rename("temp.dat", "Mobile.dat")
if found == 0:
print("Model no. not exists")
else:
print("Record Deleted")
show_all()
else:
print("File not exists")
def count_company(company):
if os.path.isfile("Mobile.dat"):
fobj=open("Mobile.dat", "rb")
found=0
while True:
try:
frb=pickle.load(fobj)
if frb[1] == n3:
print(frb)
found+=1
except:
break
print("the number of mobiles given by this company is", found)
fobj.close()
if found ==0:
print("Company not found")
else:
print("File not exists")
def update_price(Modelno,price):
if os.path.isfile("Mobile.dat"):
fobj=open("Mobile.dat", "rb")
temp=open("temp.dat", "wb")
found=0
while True:
try:
frb=pickle.load(fobj)
if n4 == frb[0]:
frb[2] = p
pickle.dump(frb, temp)
found=1
print("price updated")
else:
pickle.dump(frb, temp)
except:
break
fobj.close()
temp.close()
os.remove("Mobile.dat")
os.rename("temp.dat", "Mobile.dat")
if found == 0:
print("record does not exists")
else:
print("file does not exists")
#main menu
while True:
print("""
------MENU------""")
print("""1. Add record
2. Display all records
3. Search a record
4. Delete a record
5. Count no. of Mobiles given by a company
6. Update Price of Mobile
7. Exit Menu""")
ch=int(input("Enter Your Choice :"))
if ch == 1:
add_mobile()
elif ch == 2:
show_all()
elif ch == 3:
n1= int(input("Enter Model No. :"))
show_model(n1)
elif ch == 4:
n2= int(input("Enter Model No. :"))
delete_mobile(n2)
elif ch == 5:
n3=input("Enter Company Name :")
count_company(n3)
elif ch == 6:
n4=int(input("Enter the Model No. :"))
p=int(input("Enter the new Price :"))
update_price(n4,p)
elif ch == 7:
print("Thank You")
break
else:
print("Invalid Input !!!")
break