Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scissors Laurel O #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item

class Clothing(Item):

def __init__(self, condition=0):
super().__init__("Clothing", condition)

def __str__(self):
return "The finest clothing you could wear."
8 changes: 8 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from swap_meet.item import Item

class Decor(Item):
def __init__(self, condition=0):
super().__init__("Decor", condition)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of super()!


def __str__(self):
return "Something to decorate your space."
9 changes: 9 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item

class Electronics(Item):
def __init__(self, condition=0):
super().__init__("Electronics", condition)


def __str__(self):
return "A gadget full of buttons and secrets."
21 changes: 21 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Item:
def __init__(self, category = "", condition=0):
self.category = category
self.condition = condition

def __str__(self):
return "Hello World!"

def condition_description(self):
if self.condition < 1:
return "I would be cautious handling this, it's really old."
elif self.condition < 2:
return "Probably has some use still left?"
elif self.condition < 3:
return "Doesn't look like much but it will get the job done."
elif self.condition < 4:
return "This has a lot of use left!"
elif self.condition < 5:
return "Really good condition!"
else:
return "It's perfect, never used, still in orginal packaging."
53 changes: 53 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Vendor:
def __init__(self, inventory = None):
if inventory == None:
self.inventory = []
else:
self.inventory = inventory

def add(self, item):
self.inventory.append(item)
return item

def remove(self, item):
if item in self.inventory:
self.inventory.remove(item)
return item
else:
return False

def get_by_category(self, category):
matched = []
for item in self.inventory:
if item.category == category:
matched.append(item)
return matched

def swap_items(self, them, my_item, their_item):
if their_item not in them.inventory or my_item not in self.inventory:
return False
else:
self.inventory.remove(my_item)
them.inventory.append(my_item)
them.inventory.remove(their_item)
self.inventory.append(their_item)
Comment on lines +30 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the Vendor add & remove functions here.

return True

def swap_first_item(self, them):
if len(self.inventory) == 0 or len(them.inventory) == 0:
return False
return self.swap_items(them, self.inventory[0], them.inventory[0])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great code re-use!


def get_best_by_category(self, category):
items_in_category = self.get_by_category(category)
if len(items_in_category) > 0:
#lambda lets me define a func in a single line
return max(items_in_category, key = lambda item: item.condition)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat solution! I appreciate seeing all of the different versions in your commit history.

else:
return None

def swap_best_by_category(self, other, my_priority, their_priority):
my_category = self.get_best_by_category(their_priority)
their_category = other.get_best_by_category(my_priority)
total = self.swap_items(other, my_category, their_category)
return total