Skip to content

Conversation

@anjing0921
Copy link

No description provided.

def __init__(self, id=None, condition=None, fabric=None) :
super().__init__(id, condition)
if fabric:
if type(fabric) is not str:

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:

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):

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)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants