Conversation
alope107
left a comment
There was a problem hiding this comment.
Awesome job Sabrina! I especially liked the way you handled the constructors of the subclasses. This project is definitely green!
| class Clothing(Item): | ||
| def __init__(self, condition=0): | ||
| super().__init__(category="Clothing", condition=condition) |
There was a problem hiding this comment.
Awesome use of super and very clever to see you didn't need category as an argument to this subclass constructor!
| def condition_description(self): | ||
| if self.condition < 1: | ||
| return "BAD. Buy at your own risk" | ||
|
|
||
| elif self.condition < 2: | ||
| return "Not the worst. Not the best" | ||
|
|
||
| elif self.condition < 3: | ||
| return "Decent!" | ||
|
|
||
| elif self.condition < 4: | ||
| return "Pretty good" | ||
|
|
||
| elif self.condition <= 5: | ||
| return "Good" | ||
|
|
||
| else: | ||
| return "Try again!" |
There was a problem hiding this comment.
Nice job defining this here once and having the subclasses inherit from it.
| def __init__(self, inventory=[]): | ||
| self.inventory = copy.copy(inventory) |
There was a problem hiding this comment.
I like how you make a copy of the inventory here! This is a good defensive programming practice that prevents others from messing around with our inventory inadvertently after passing it to us.
| def remove(self, item): | ||
| if item not in self.inventory: | ||
| return False | ||
| else: | ||
| self.inventory.remove(item) | ||
| return item |
There was a problem hiding this comment.
Because the if block returns, we don't need the else. we could just write:
def remove(self, item):
if item not in self.inventory:
return False
self.inventory.remove(item)
return item
| def get_by_category(self, category): | ||
| items = [item for item in self.inventory if item.category == category] | ||
| return items |
There was a problem hiding this comment.
Nice use of a comprehension! One small thing: because we immediately return the variable, we could just say
return [item for item in self.inventory if item.category == category]
| def swap_first_item(self, other_vendor): | ||
| if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: | ||
| return False | ||
|
|
||
| vendor_first_item = self.inventory[0] | ||
| friend_first_item = other_vendor.inventory[0] | ||
|
|
||
| self.swap_items(other_vendor, vendor_first_item, friend_first_item) | ||
|
|
||
| return True |
There was a problem hiding this comment.
Great re-use of your earlier functions!
| def get_best_by_category(self, category): | ||
| items = self.get_by_category(category) | ||
| best_item = None | ||
| for item in items: | ||
| if best_item is None or item.condition > best_item.condition: | ||
| best_item = item | ||
| return best_item |
| assert result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
|
|
||
| assert item_f in tai.inventory | ||
| assert item_a in tai.inventory | ||
| assert item_b in tai.inventory | ||
|
|
||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory | ||
| assert item_c in jesse.inventory |
No description provided.