Conversation
| if 0 <= self.condition <= 5: | ||
| self.condition = float(condition) | ||
| else: | ||
| raise ValueError("Condition must range from 0-5.") |
There was a problem hiding this comment.
If you're going to raise an error, I'd do it as early as possible, to avoid executing unnecessary code :)
| raise ValueError("Condition must range from 0-5.") | ||
|
|
||
| def get_category(self): | ||
| return f"{self.__class__.__name__}" |
There was a problem hiding this comment.
nice use of python introspection!
| item_summary = f"An object of type {self.get_category()} with id {self.id}" | ||
| return item_summary | ||
|
|
||
| def condition_description(self): |
There was a problem hiding this comment.
Love the descriptions here :)
Though, you probably now could see that a dict might be useful here: for n conditions to check, a dict will be O(1) lookup, vs worse case O(n) to fall through all of the if/else conditions to the last one.
| pass No newline at end of file | ||
|
|
||
| def __init__(self, inventory=None): | ||
| self.inventory = inventory if inventory is not None else [] |
There was a problem hiding this comment.
nice example of using a ternary operator :)
| def swap_items(self, other_vendor, my_item, their_item): | ||
| if (my_item not in self.inventory or their_item not in other_vendor.inventory): | ||
| return False | ||
| else: |
There was a problem hiding this comment.
small point:
starting a function with if... return can be considered a "guard". There's no need for the else and indentation, as the only way the code executes is if it didn't go down the return path. This can be cleaner, and minimize extra indentation :)
No description provided.