Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff05862

Browse files
To Ram - as discussed on shopping cart
1 parent 0cb151d commit ff05862

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

‎FruitStore/FStore.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import time, sys
2+
3+
class FStore:
4+
5+
6+
def __init__(self, stock={}):
7+
"""
8+
Our constructor class that instantiates fruit store.
9+
"""
10+
self.stock = stock
11+
12+
def displayStock(self):
13+
"""
14+
Displays the fruits currently available for purchase in the store.
15+
"""
16+
17+
# for fruits, quantity in self.stock.items():
18+
# print(" We currently have {} {} in store".format(quantity, fruits), end="\n")
19+
20+
# return None
21+
22+
# Sanjay's code
23+
for fruits, quantity in self.stock.items():
24+
print("we have " + str(quantity) + " of " + fruits)
25+
26+
return '\n'
27+
28+
def getStockFromStore(self):
29+
return self.stock
30+
31+
def listOfFruits(self):
32+
# self.Fruits = [fruits for fruits in self.stock.keys()]
33+
# return self.Fruits
34+
35+
# Sanjay's code
36+
return list(self.stock.keys())
37+
38+
39+
def timeDelay(self):
40+
self.time = time.sleep(5)
41+
return self.time
42+
43+
def callExit(self):
44+
self.exit = sys.exit(0)
45+
return self.exit
46+
47+
def numberOfFruits(self, number):
48+
49+
# if number <= 0:
50+
# print("Number of fruits should be positive!")
51+
# return None
52+
# elif n > self.stock.values()[0]
53+
pass
54+
55+
def cart(self):
56+
# cart logic
57+
pass
58+
59+
60+
61+
# TODO: 3 - crate a class called ShoppingCart
62+
# addToCart
63+
# ṛemoveFromCart
64+
# getListOfItemsFromCart
65+

‎FruitStore/__init__.py

Whitespace-only changes.

‎FruitStore/main.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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()

‎FruitStore/stock.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Apple": 100,
3+
"Banana": 70,
4+
"Cherry": 23,
5+
"orange": 254
6+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /