Skip to content

Instantly share code, notes, and snippets.

@abdulateef
Created September 12, 2017 10:18
Show Gist options
  • Save abdulateef/7812e81e213be54f2c99ae3a5877aa5f to your computer and use it in GitHub Desktop.
Save abdulateef/7812e81e213be54f2c99ae3a5877aa5f to your computer and use it in GitHub Desktop.
class ShoppingCart(object):
def __init__(self):
self.total = 0
self.items = {}
def add_item(self, item_name, quantity, price):
self.total += price*quantity
self.items.update({item_name: quantity})
def remove_item(self, item_name, quantity, price):
if quantity >= self.items[item_name] and quantity >= 1:
items_cost = price * self.items[item_name]
self.total -= items_cost
del self.items[item_name]
else:
self.total -= quantity * price
self.items[item_name] -= quantity
def checkout (self, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment