Python Forum
Want a solution to this
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want a solution to this
#5
this is what i come up with

class ShoppingCart:
    items = {}
    def __init__(self, total = 0):
        self.total = total
    def add_item(self, item_name, quantity, price):
        self.item_name = item_name
        self.quantity = quantity
        self.price = price
        if not item_name in self.items:
            self.items[item_name] = quantity
        total = self.price*self.quantity + self.total
        self.items[self.item_name] = self.quantity
    def remove_item(self, item_name, quantity, price):
        self.item_name = item_name
        self.quantity = quantity
        self.price = price
        total = self.total - price*quantity
        if item_name in self.items:
            del self.items[item_name]
            return self.items
    def checkout(self, cash_paid):
        self.cash_paid = cash_paid
        return self.total - cash_paid
        if cash_paid < self.total:
            return "Cash paid not enough"
class Shop(ShoppingCart):
    def __init__(self):
        self.quantity = 100

    def remove_item(self, quantity):
        self.quantity -= quantity
        return self.quantity
Reply


Messages In This Thread
Want a solution to this - by Shazily - Feb-05-2017, 12:44 AM
RE: Want a solution to this - by Ofnuts - Feb-05-2017, 12:56 AM
RE: Want a solution to this - by Shazily - Feb-05-2017, 06:59 AM
RE: Want a solution to this - by wavic - Feb-05-2017, 07:01 AM
RE: Want a solution to this - by wavic - Feb-05-2017, 07:30 AM
RE: Want a solution to this - by Shazily - Feb-05-2017, 07:14 AM
RE: Want a solution to this - by buran - Feb-05-2017, 09:50 AM
RE: Want a solution to this - by Shazily - Feb-05-2017, 10:35 AM
RE: Want a solution to this - by nilamo - Feb-06-2017, 05:08 AM
RE: Want a solution to this - by buran - Feb-06-2017, 09:45 AM
RE: Want a solution to this - by Div - Mar-12-2018, 01:11 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020