-
Notifications
You must be signed in to change notification settings - Fork 21
Ocelots Anna Du #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Ocelots Anna Du #17
Conversation
| def __init__(self, id=None, condition=None, fabric=None) : | ||
| super().__init__(id, condition) | ||
| if fabric: | ||
| if type(fabric) is not str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice extra error checking!
I would do this before the other code, so that the error is generated first, before extra work is unnecessarily done.
| def __init__(self, id=None, condition=None, type=None) : | ||
|
|
||
| super().__init__(id, condition) | ||
| if type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clean code, though it could be a ternary operator.
|
|
||
| return f"An object of type Item with id {self.id}" | ||
|
|
||
| def condition_description(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done-- though now, you probably can see the advantages of a dict for this. O(1) lookup, vs, O(n) for the worse case of falling through n conditions in an if/else :)
| if my_item not in self.inventory or their_item not in b_vendor.inventory : | ||
| return False | ||
| else: | ||
| self.remove(my_item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good use of making use of existing vendor functions, rather than re-implementing that logic here again!
No description provided.