Conversation
apradoada
left a comment
There was a problem hiding this comment.
GREEN! Well done, Elzara! I am so sorry for the late feedback, but honestly, this project shows me that you have a really good grasp of python. You've used ternaries and list comprehensions in all the places you needed to and your optional enhancements and tests all look really great! Well done!
|
|
||
| def __str__(self): | ||
| parent_str = super().__str__() | ||
| return f"{parent_str} It is made from {self.fabric} fabric." |
There was a problem hiding this comment.
I really like the way you've parsed out the parent_str here. Feel free to skip that step and just include the super().__str__() in the f String!
|
|
||
| def __str__(self): | ||
| parent_str = super().__str__() | ||
| return f"{parent_str} It takes up a {self.width} by {self.length} sized space." |
There was a problem hiding this comment.
This function looks great! Good use of the default parameters!
|
|
||
| def __str__(self): | ||
| parent_str = super().__str__() | ||
| return f"{parent_str} This is a {self.type} device." |
| class Item: | ||
| pass No newline at end of file | ||
| def __init__(self, id=None, condition=0, age=0): | ||
| self.id = uuid.uuid4().int if id is None else id |
| elif x < 5: | ||
| return "Almost new, if you squint hard enough." | ||
| else: | ||
| return "Mint condition! Did you steal this from a time machine?" |
There was a problem hiding this comment.
Your Item class looks really good too! I love the descriptions you have for your conditions! I also appreciate that you have given ranges for each condition description! this allows for a wider range of possibilities!
| best_item = None | ||
| for item in items: | ||
| if best_item is None or item.condition > best_item.condition: | ||
| best_item = item |
There was a problem hiding this comment.
A super small tweak, but if we can avoid having to check and see if best_item is None along with the more important condition of comparing the conditions, we should try that!
| best_from_other = other_vendor.get_best_by_category(my_priority) | ||
| best_from_self = self.get_best_by_category(their_priority) | ||
|
|
||
| return self.swap_items(other_vendor, best_from_self, best_from_other) |
| def find_newest_item(self, items): | ||
| if not items: | ||
| return None | ||
|
|
||
| newest_item = None | ||
| for item in items: | ||
| if newest_item is None or item.age < newest_item.age: | ||
| newest_item = item | ||
|
|
||
| return newest_item | ||
|
|
||
| def swap_by_newest(self, other_vendor): | ||
| my_new_item = self.find_newest_item(self.inventory) | ||
| their_new_item = self.find_newest_item(other_vendor.inventory) | ||
|
|
||
| if not my_new_item or not their_new_item: | ||
| return False | ||
|
|
||
| return self.swap_items(other_vendor, my_new_item, their_new_item) No newline at end of file |
There was a problem hiding this comment.
Thank you for adding in these optional enhancements! They look really good!
| assert len(jesse.inventory) == 3 | ||
| assert item_a in jesse.inventory | ||
| assert item_d in tai.inventory | ||
| assert item_b in tai.inventory No newline at end of file |
There was a problem hiding this comment.
Your optional test suite looks great!
| assert len(items) == 0 | ||
| assert items == [] |
There was a problem hiding this comment.
These two asserts are testing for a very similar outcome. I would argue that only one over the other is needed! Specifically, I would check for the empty list as that covers your other assert as well!
No description provided.