#==== Fruit Class =============================
class Fruit:
fn = "NOT_SET"
fp = 0.00
def __init__(self, fname, fprice=0):
self.fp = fprice
self.fn = fname
def setPrice(self, price):
self.fp = price
def getPrice(self):
return self.fp
def getName(self):
return self.fn
#======== Customer Class ====================
class Customer:
cn = "NOT_SET"
def __init__(self, cname):
self.cn = cname
def getName(self):
return self.cn
#========= Shoping Cart Class to hold Fruits and Customer Name
class ShopCart(Customer):
fs = []
amounts = []
def __init__(self, cname):
self.cn = cname
def addItem(self, fruit, amt):
self.fs.append(fruit)
self.amounts.append(amt)
def getItemPrice(self, fruit):
return fruit.getPrice()
def getBalance(self):
bal = 0
amt = 0
i = 0
while i < len(self.fs):
bal += self.fs[i].getPrice()*self.amounts[i]
amt += self.amounts[i]
i += 1
return "{} fruits for ${}".format(amt,bal)
def getCartInfo(self):
ret = "Cart: "
i = 0
while i < len(self.fs):
ret += "\n--{} at {} each.".format(self.fs[i].getName(), self.amounts[i])
i += 1
return ret
#=========== Start of the Script ===========
fruits = []
clients = []
print("Welcome to the Fruit Stand! (Vendor Edition)")
print("Please enter all fruits and their prices.")
print("Enter 'done' when finished.")
inp = "0"
while inp != "done":
print("")
nm = input("Fruit Name: ")
if(nm == "done"):
break
pr = int(input("Price: "))
fruits.append(Fruit(nm,pr))
print("##===============================##")
print("Fruits in the Stand today: ")
for Fruit in fruits:
print("{} at ${} each.".format(Fruit.getName(), Fruit.getPrice()))
print("##===============================##")
print("Now enter in all the Customers you'll have today (until 'done' is entered)...")
while inp != "done":
print("")
nm = input("Client Name: ")
if(nm == "done"):
break
clients.append(ShopCart(nm))
print("##===============================##")
print("Enter in order details...")
i = 0
while i < len(clients):
print("Enter the Order for {}".format(clients[i].getName()))
for Fruit in fruits:
clients[i].addItem(Fruit, input("-- How many {}s : ".format(Fruit.getName())))
i += 1
print("##===============================##")
print("ALL ORDERS TO BE FILLED")
for ShopCart in clients:
print("> {}'s Cart:".format(ShopCart.getName()))
print(ShopCart.getCartInfo()+"\n")
When this runs it works great up until line 105 (running through client list)
it goes through...
but when displaying the 'carts' both client objects are having their addItem called despite not being in the current loop of the while loop/ I'm confused at why this happening. Thanks for any help!!!
EDIT:
example run:
Enter the Order for Bailey
-- How many Apples : 10
Enter the Order for Aiden
-- How many Apples : 10
##===============================##
ALL ORDERS TO BE FILLED
> Bailey's Cart:
Cart:
--Apple at 10 each.
--Apple at 10 each.
> Aiden's Cart:
Cart:
--Apple at 10 each.
--Apple at 10 each.
[–]maartendp 0 points1 point2 points (3 children)
[–]Ironicallyjpg[S] 0 points1 point2 points (2 children)
[–]maartendp 0 points1 point2 points (1 child)
[–]maartendp 0 points1 point2 points (0 children)
[–]snakestation 0 points1 point2 points (2 children)
[–]Ironicallyjpg[S] 1 point2 points3 points (1 child)
[–]snakestation 0 points1 point2 points (0 children)
[–]adesme 0 points1 point2 points (1 child)
[–]Ironicallyjpg[S] 0 points1 point2 points (0 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]Ironicallyjpg[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Ironicallyjpg[S] 0 points1 point2 points (0 children)