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 // Raquel Mena #51

Open
wants to merge 6 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
8 changes: 8 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .item import Item

class Clothing(Item):

Choose a reason for hiding this comment

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

Good use of inheritance/super()

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 .item import Item

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

def __str__(self):
return "Something to decorate your space."
8 changes: 8 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .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."
26 changes: 26 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

class Item:
def __init__(self, category='', condition=0): #an inventory has to be passed in
self.category = category
self.condition = condition
#self.get_by_category
def __str__(self):
return 'Hello World!'

def condition_description(self):
# for items in self.category:
if self.condition == 0:
return "You probably want to use a glove for this one"
if self.condition == 1:
return "Heavily used."
if self.condition == 2:
return "Heavily used."
if self.condition == 3:
return "Standard wear and tear."
if self.condition == 4:
return "*Almost* like new."
if self.condition == 5:
return "Like new"
else:
return "nope"

71 changes: 71 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

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 not in self.inventory:
return False
if item in self.inventory:
self.inventory.remove(item)
return item

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

return matching_items

def swap_items(self, friend, my_item, friends_item):
if my_item in self.inventory and friends_item in friend.inventory:
# friend.add(self.remove(my_item))
# self.add(friend.remove(friends_item))
self.remove(my_item)
friend.add(my_item)
friend.remove(friends_item)
self.add(friends_item)
Comment on lines +33 to +36

Choose a reason for hiding this comment

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

great use of add and remove as helper function

return True
else:
return False
Comment on lines +30 to +39

Choose a reason for hiding this comment

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

Consider reorganizing like this to deal with the edge case first and move the main logic of the function out from being nested.

Suggested change
if my_item in self.inventory and friends_item in friend.inventory:
# friend.add(self.remove(my_item))
# self.add(friend.remove(friends_item))
self.remove(my_item)
friend.add(my_item)
friend.remove(friends_item)
self.add(friends_item)
return True
else:
return False
if my_item not in self.inventory or friends_item not in friend.inventory:
return False
self.remove(my_item)
friend.add(my_item)
friend.remove(friends_item)
self.add(friends_item)
return True




def swap_first_item(self, friend):

if len(self.inventory) == 0 or len(friend.inventory) == 0:
return False
else:
self.swap_items(friend, self.inventory[0], friend.inventory[0])
return True
Comment on lines +48 to +49

Choose a reason for hiding this comment

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

Consider moving this outside of the else clause.


def get_best_by_category(self, category):
list_of_categorys = self.get_by_category(category)
if not list_of_categorys:
return None
top_condition = -1
top_item = None
for item in list_of_categorys:
if item.condition > top_condition:
top_condition = item.condition
top_item = item
return top_item

def swap_best_by_category(self, other, my_priority, their_priority):
item_for_other = self.get_best_by_category(their_priority)
item_for_self = other.get_best_by_category(my_priority)
if item_for_other and item_for_self:
self.swap_items(other, item_for_other, item_for_self)
return True
else:
return False