Created
October 4, 2018 04:57
-
-
Save shreezan123/26e1de0069999fef2cb9124f23c406e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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