-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_demo.py
40 lines (35 loc) · 975 Bytes
/
json_demo.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
def main():
while True:
print('Menu'.center(50,'*'))
secim = input('1- Add Medicine \n2- Get Medicines\n3- Exit\n ')
if secim == '3':
break
else:
if secim == '1':
inputAdd()
elif secim == '2':
getMedicine()
else:
print('wrong choice')
def inputAdd():
medName= input( "Name:")
medPrice= input( "Price:")
onSale= input( "On sale:")
addMedicine(medName,medPrice,onSale)
def addMedicine(name,price,sale):
meds=[]
med = {
"medName": name,
"price": price,
"sale": sale,
}
meds.append(med)
import json
with open("medicines.json","w") as file:
json.dump(meds,file,ensure_ascii=False,indent=2)
def getMedicine():
import json
with open("medicines.json") as file:
meds = json.load(file)
print(meds)
main()