Conversation
ameerrah9
left a comment
There was a problem hiding this comment.
Congratulations on completing this project Cintia and Ryan! There's some impressive code in here, and it's very clean and easy to read. Great use of helper methods in the Vendor class! Excellent work using inheritance to create the children classes!
| from swap_meet.item import Item | ||
| # creates class/category Clothing using class Item | ||
| # stringifies Clothing | ||
| class Clothing(Item): |
There was a problem hiding this comment.
Amazing work completing your project yall! This inheritance is sweet and the comment clearly explains what your method's objective is 💯
There was a problem hiding this comment.
Excellent work with these default arguments
| from swap_meet.item import Item | ||
| # creates class/category Decor using class Item | ||
| # stringifies Decor | ||
| class Decor(Item): |
| from swap_meet.item import Item | ||
| # creates class/category Electronics using class Item | ||
| # stringifies Electronics | ||
| class Electronics(Item): | ||
| def __init__(self, category="Electronics", condition=0): | ||
| self.category = category | ||
| self.condition = condition |
| if category is None: | ||
| category = "" | ||
| self.category = category |
There was a problem hiding this comment.
Good job using this default parameter of None. None is often used as a default argument value in Python because it allows us to call the function without providing a value for an argument that isn't required on each function invocation. Here's the article I referenced: https://bobbyhadz.com/blog/python-using-none-as-default-argument#:~:text=None%20is%20often%20used%20as,for%20list%20and%20dict%20arguments.
You could refactor this to a shorthand (one-liner): self.category = category if category is not None else ""
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "Horrible Condition >:(" | ||
| elif self.condition == 1: | ||
| return "Heavily Used :(" | ||
| elif self.condition == 2: | ||
| return "So-So condition :/" | ||
| elif self.condition == 3: | ||
| return "Decent :|" | ||
| elif self.condition == 4: | ||
| return "Gently Used :)" | ||
| elif self.condition == 5: | ||
| return "Like New! >:)" |
There was a problem hiding this comment.
Nice way to implement your description! It uses conditional flow pretty well
| def get_by_category (self, category): | ||
| if not category: | ||
| return None | ||
| matching_items = [] | ||
| for item in self.inventory: | ||
| if item.category == category: | ||
| matching_items.append(item) | ||
| return matching_items |
| def swap_items(self, friend, my_item, their_item): | ||
| if my_item in self.inventory and their_item in friend.inventory: | ||
| self.add(their_item) | ||
| friend.add(my_item) | ||
| self.remove(my_item) | ||
| friend.remove(their_item) | ||
| return True | ||
| return False |
| def get_best_by_category(self, category): | ||
| inventory = self.get_by_category(category) | ||
| if not inventory: | ||
| return None | ||
| highest = 0 | ||
| best_item = None | ||
| for item in inventory: | ||
| if item.condition > highest: | ||
| highest = item.condition | ||
| best_item = item | ||
| return best_item |
There was a problem hiding this comment.
Nice job connecting what you learned from the Problem Solving Exercise 👍🏾
| assert result == False | ||
|
|
||
| assert len(vendor.inventory) == 3 | ||
| assert "a" in vendor.inventory | ||
| assert "b" in vendor.inventory | ||
| assert "c" in vendor.inventory |
There was a problem hiding this comment.
You can check the result more pythonically but checking for the falseyness!
| assert result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
|
|
||
| assert item_a in tai.inventory | ||
| assert item_b in tai.inventory | ||
| assert item_f in tai.inventory | ||
| assert item_c in jesse.inventory | ||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory |
No description provided.