1
+ from FStore import FStore
2
+
3
+ # TODO 1 - get stock from reading a json file.
4
+ dict = {'Apple' :100 , 'Banana' : 100 , 'Cherry' : 100 }
5
+ # Write a function to read stock json file
6
+ # function should return json info which is there in the file.
7
+
8
+
9
+ # TODO 2 - pass the return of above function, to open your store
10
+ openStore = FStore (dict ) # you cannot open a store without stock.
11
+
12
+ def getUserInput (fromWhichMenu ):
13
+
14
+ if fromWhichMenu == "fromMainMenu" :
15
+ try :
16
+ choice = input ("Please enter your choice : " ).strip ()
17
+ except ValueError :
18
+ print ("That's not an int!" )
19
+ return choice
20
+ elif fromWhichMenu == "fruitMenu" :
21
+ try :
22
+ choice = input ("Please enter your choice : " ).strip ()
23
+ except ValueError :
24
+ print ("That's not an int!" )
25
+ return choice
26
+ elif fromWhichMenu == "numbers" :
27
+ try :
28
+ choice = input ("how many you need? " ).strip ()
29
+ except ValueError :
30
+ print ("That's not an int!" )
31
+
32
+ return choice
33
+ elif fromWhichMenu == "addOrRemove" :
34
+ try :
35
+ choice = input ("Is there anything you want to add or remove? Y or N " ).strip ()
36
+ if choice == "Y" :
37
+ return True
38
+ else :
39
+ return False
40
+ except ValueError :
41
+ print ("That's not an int!" )
42
+
43
+
44
+
45
+ def displayMainMenu ():
46
+ print ("""
47
+ ====== Fruit Shop =======
48
+ 1. Display available Stocks
49
+ 2. Buy Fruits
50
+ 3. Get Total
51
+ 4. Checkout
52
+ 5. Exit
53
+ """ )
54
+
55
+ def displayFruitMenu ():
56
+ for i in enumerate (openStore .listOfFruits (), start = 1 ):
57
+ print (i [0 ], i [1 ])
58
+
59
+ def shoppingCart ():
60
+ pass
61
+
62
+ def storeOpens ():
63
+ # while True:
64
+ cart = {}
65
+ displayMainMenu ()
66
+ choice = getUserInput ("fromMainMenu" )
67
+
68
+ if choice == '1' :
69
+ openStore .displayStock ()
70
+ print ("\n please select from above available stock" , end = "\n " )
71
+ elif choice == '2' :
72
+ print ("\n What do you want to buy?\n " )
73
+ displayFruitMenu ()
74
+ choice = getUserInput ("fruitMenu" )
75
+
76
+ if choice == '1' :
77
+ availableStock = openStore .getStockFromStore ()
78
+ count = int (getUserInput ("numbers" ))
79
+
80
+ if count <= availableStock ['Apple' ]:
81
+ cart ['Apple' ] = count
82
+ availableStock ['Apple' ] = availableStock ['Apple' ] - count
83
+ print (availableStock )
84
+
85
+ print ("Here's your items in cart , " , cart )
86
+ # wannaBuyMore = getUserInput("addOrRemove")
87
+ # if (wannaBuyMore):
88
+ # fruitChoice = getUserInput("fruitMenu")
89
+
90
+ # else:
91
+ # print("Done")
92
+
93
+
94
+ elif choice == '2' :
95
+ pass
96
+ elif choice == '3' :
97
+ pass
98
+
99
+ elif choice == 5 :
100
+ pass
101
+ else :
102
+ print ("Invalid input. Please enter number between 1-5 " )
103
+
104
+
105
+ if __name__ == "__main__" :
106
+ storeOpens ()
0 commit comments