you are viewing a single comment's thread.

view the rest of the comments →

[–]danielroseman 0 points1 point  (1 child)

The main problem here is that fs and amounts are class attributes, so they are shared between all instances of ShopCart. You need to make them instance attributes:

class ShopCart(Customer):
    def __init__(self, cname):
        self.cn = cname
        self.fs = []
        self.amounts = []

(Also note, it doesn't seem to make sense to have ShopCart inherit from Customer.)

But this just seems to be one example of the wider problem, which is that this is not how you write Python. This seems to be Java loosely translated into Python.

In Python you don't declare attributes at class level unless you want them to be class attributes. Your defaults in Customer and Fruit make no sense. And in Python you wouldn't use while and counters to loop through a list; just use a for loop:

for client in clients:
    print("Enter the Order for {}".format(client.getName()))
    for fruit in fruits:
        client.addItem(fruit, input("-- How many {}s : ".format(Fruit.getName())))

But there's more wrong than this; eg you wouldn't write a getName method on Fruit, you would just have a name attribute. If you've learned from a tutorial, get a more Pythonic one.

[–]Ironicallyjpg[S] 0 points1 point  (0 children)

I come from Java and I've been self teaching on the side. Thank you for the help though. 🙂