<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Naming conventions
The python community has some naming convections, defined in PEP-8
Step2:  This module has a special section, starting with
Step4:  Item
Here's the start of an item class -- we want it to hold the name and quantity.  
You should have the following features
Step5:  Here are some tests your code should pass
Step6:  How do they behave in a list?
Step11:  ShoppingCart
Now we want to create a shopping cart.  The main thing it will do is hold a list of items.
Step12:  Here are some tests
<ASSISTANT_TASK:>
Python Code:
import vector2d
u = vector2d.Vector(1,2)
u
Explanation: Naming conventions
The python community has some naming convections, defined in PEP-8:
https://www.python.org/dev/peps/pep-0008/
The widely adopted ones are:
class names start with an uppercase, and use "camelcase" for multiword names, e.g. ShoppingCart
varible names (including objects which are instances of a class) are lowercase and use underscores to separate words, e.g., shopping_cart
module names should be lowercase with underscores
Modules
This class is useful to other codes, not just this notebook.  This is where modules come in -- we can put all of this code into a .py file and then import it to use its functionality.  Here, it is called vector2d.py:
End of explanation
INVENTORY_TEXT = 
apple, 0.60
banana, 0.20
grapefruit, 0.75
grapes, 1.99
kiwi, 0.50
lemon, 0.20
lime, 0.25
mango, 1.50
papaya, 2.95
pineapple, 3.50
blueberries, 1.99
blackberries, 2.50
peach, 0.50
plum, 0.33
clementine, 0.25
cantaloupe, 3.25
pear, 1.25
quince, 0.45
orange, 0.60
# this will be a global -- convention is all caps
INVENTORY = {}
for line in INVENTORY_TEXT.splitlines():
    if line.strip() == "":
        continue
    item, price = line.split(",")
    INVENTORY[item] = float(price)
INVENTORY
Explanation: This module has a special section, starting with:
if __name__ == "__main__":
This tests whether we are executing the code directly, e.g., as python3 vector2d.py instead of importing it.  This allows us to put some tests, demonstrations, etc. directly in the module.
Practicing Classes
Exercise 1 (shopping cart)
Let's write a simple shopping cart class -- this will hold items that you intend to purchase as well as the amount, etc.  And allow you to add / remove items, get a subtotal, etc.
We'll use two classes: Item will be a single item and ShoppingCart will be the collection of items you wish to purchase.
First, our store needs an inventory -- here's what we have for sale:
End of explanation
class Item(object):
     an item to buy 
    
    def __init__(self, name, quantity=1):
        if name not in INVENTORY:
            raise ValueError
        self.name = name
        self.quantity = quantity
        
    def __repr__(self):
        pass
        
    def __eq__(self, other):
        pass
    
    def __add__(self, other):
        pass
Explanation: Item
Here's the start of an item class -- we want it to hold the name and quantity.  
You should have the following features:
the name should be something in our inventory
Our shopping cart will include a list of all the items we want to buy, so we want to be able to check for duplicates.  Implement the equal test, ==, using __eq__
we'll want to consolidate dupes, so implement the + operator, using __add__ so we can add items together in our shopping cart.  Note, add should raise a ValueError if you try to add two Items that don't have the same name.
Here's a start:
End of explanation
a = Item("apple", 10)
b = Item("banana", 20)
c = Item("apple", 20)
# won't work
a + b
# will work
a += c
a
a == b
a == c
Explanation: Here are some tests your code should pass:
End of explanation
items = []
items.append(a)
items.append(b)
items
c in items
Explanation: How do they behave in a list?
End of explanation
class ShoppingCart(object):
    
    def __init__(self):
        self.items = []
        
    def subtotal(self):
         return a subtotal of our items 
        pass
    def add(self, name, quantity):
         add an item to our cart 
        pass
        
    def remove(self, name):
         remove all of item name from the cart 
        pass
        
    def report(self):
         print a summary of the cart 
        pass
Explanation: ShoppingCart
Now we want to create a shopping cart.  The main thing it will do is hold a list of items.
End of explanation
sc = ShoppingCart()
sc.add("orange", 19)
sc.add("apple", 2)
sc.report()
sc.add("apple", 9)
sc.report()
sc.subtotal()
sc.remove("apple")
sc.report()
Explanation: Here are some tests
End of explanation
<END_TASK>