Uploaded by Ryan Burns

Python Debug Homework

advertisement
In [10]:
class BOX: #BOX needs to have the same capitalization as in the next cell
"""A BOX object class. Has a name and a list of contents.
Attributes:
name (str): the name of the backpack's owner.
contents (list): the contents of the backpack.
"""
def __init__(self, company, headquarters, address):
"""Set the name and initialize an empty list of contents.
Parameters:
name (str): the name of the backpack's owner.
"""
self.company = company
# Initialize some attributes.
self.address = address
# Initialize some attributes.
self.headquarters = headquarters
# HEADQUARTERS WAS NOT INITIALIZED
self.contents = []
def place(self, item):
"""Add 'item' to the box's list of contents."""
self.contents.append(item) # Use 'self.contents', not just 'contents'.
def remove(self, item):
"""Remove 'item' from the box's list of contents."""
self.contents.remove(item)
In [11]: Package = BOX("Apple Inc.","Cupertino, CA","1 Infinite Loop Cupertino")
print(Package.company,Package.headquarters,Package.address)
# Add some items to the BOX object.
Package.place("Macbook Pro") #Put should be changed place
Package.place("iPhone")
# Remove an item from the Package.
Package.remove("iPhone") #Take should be changed to remove
Package.contents
print("A package with", Package.contents, "is delievered to", Package.company)
Apple Inc. Cupertino, CA 1 Infinite Loop Cupertino
A package with ['Macbook Pro'] is delievered to Apple Inc.
In [ ]:
Download