Skip to content

Instantly share code, notes, and snippets.

@shreezan123
Created October 4, 2018 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shreezan123/26e1de0069999fef2cb9124f23c406e9 to your computer and use it in GitHub Desktop.
Save shreezan123/26e1de0069999fef2cb9124f23c406e9 to your computer and use it in GitHub Desktop.
class ShoppingList:
cart = {}
def __init__(self):
pass
def add_item(self,name,price):
self.cart[name] = price
def remove_item(self,name):
if name in self.cart:
del(self.cart[name])
def get_total(self):
s = 0
for items in self.cart:
s+=self.cart[items]
return s
walmart = ShoppingList()
walmart.add_item("shampoo",5)
walmart.add_item("banana",2)
walmart.add_item("bicycle",100)
print walmart.get_total()
walmart.remove_item("banana")
print walmart.get_total()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment