Python Forum
Want a solution to this
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want a solution to this
#11
This is what i tried, it should help
class ShoppingCart:
    items = {}
    totals = []
    def __init__(self, total=0):
        self.total = total
        self.items = {}

    def add_item(self, item_name, quantity, price):
        self.item_name = item_name
        self.quantity = quantity
        self.price = price
        self.total += price * quantity
        self.items.update({item_name : quantity})

    def remove_item(self, item_name, quantity, price):
        self.item_name = item_name
        self.quantity = quantity
        self.price = price
        if item_name in self.items:
            if quantity < self.items[item_name] and quantity > 0:
                self.items[item_name] -= quantity
                self.total -= price * quantity
        elif quantity >= self.items[item_name]:
            self.total -= price * self.items[item_name]
            del self.items[item_name]


    def checkout(self, cash_paid):
        self.cash_paid = cash_paid
        if cash_paid >= self.total:
            return cash_paid - self.total
        return "Cash paid not enough"



class Shop(ShoppingCart):
    def __init__(self):
        self.quantity = 100

    def remove_item(self):
        self.quantity -= 1
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