Conversation
alope107
left a comment
There was a problem hiding this comment.
Great job K! Very nice use of inheritance and re-use of methods. You've written some really DRY code here! This submission is green~
| class Clothing(Item): | ||
| def __init__(self, category = "Clothing", condition = 0): | ||
| super().__init__(category, condition) |
There was a problem hiding this comment.
Great use of super here! Consider removing the category from the constructor arguments on line 3. We know we always want it to be "Clothing" so we don't want to allow changing it when instantiating an instance.
| def __init__(self, category = "Electronics", condition = 0): | ||
| super().__init__(category, condition) |
There was a problem hiding this comment.
Tiny style point here and elsewhere: when defining default arguments don't include spaces on either side of the equals sign. We would instead write it like:
def __init__(self, category="Electronics", condition=0):
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "Poor" | ||
| if self.condition == 1: | ||
| return "Fair" | ||
| if self.condition == 2: | ||
| return "Good" | ||
| if self.condition == 3: | ||
| return "Very good" | ||
| if self.condition == 4: | ||
| return "Like new" | ||
| if self.condition ==5: | ||
| return "New" No newline at end of file |
There was a problem hiding this comment.
Great job having this be defined here once and inherited by the child classes!
| def add(self, item): | ||
| '''Adds an item to a vendor's inventory''' | ||
| self.inventory.append(item) | ||
| return item |
| def __init__(self, inventory=None): | ||
| if not inventory: | ||
| inventory = [] | ||
| self.inventory = inventory |
There was a problem hiding this comment.
Nice job avoiding a mutable default object.
| def get_by_category(self, category): | ||
| "Returns a list of items of a category in a vendor's inventory" | ||
| item_list = [item for item in self.inventory if item.category == category] | ||
| return item_list |
| def swap_first_item(self, vendor): | ||
| '''Swaps the first item in two vendor inventories (self and vendor)''' | ||
| if self.inventory and vendor.inventory: | ||
| return self.swap_items(vendor, self.inventory[0], vendor.inventory[0]) |
There was a problem hiding this comment.
Love how you re-use your earlier method! One small bug here: according to the README this method should return False if either of the inventories is empty, but it actually returns None.
| def get_best_by_category(self, category): | ||
| '''Returns the best item in vendor inventory by category. If multiple items, returns the item with the highest condition''' | ||
| items_list = self.get_by_category(category) | ||
| if not items_list: | ||
| return None | ||
| best_item = items_list[0] | ||
| for item in items_list: | ||
| if item.condition > best_item.condition: | ||
| best_item = item | ||
| return best_item |
There was a problem hiding this comment.
Great logic and re-use of method here!
| assert result == "c" | ||
| assert vendor.inventory == ["a", "b"] |
| # - That the results is truthy | ||
| assert not result |
There was a problem hiding this comment.
Looks like you may have accidentally copied a comment that says the opposite of what you want.
No description provided.