-
Notifications
You must be signed in to change notification settings - Fork 71
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
Rock-lin #58
base: master
Are you sure you want to change the base?
Rock-lin #58
Conversation
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.
Great job Lin! Your code was easy to read and you hit all the learning goals. I added some comments about code style and refactoring.
Well done, keep up the good work! 🥳
class Clothing(Item): | ||
def __init__(self, category="Clothing", condition=0): | ||
super().__init__(category, condition) |
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.
Great use of the super constructor!
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.
However, it's still possible to accidentally override category
in the instance constructor. You are right in using a default argument assign "Clothing" to category, however, we can move that code over to the super constructor instead.
class Clothing(Item): | |
def __init__(self, category="Clothing", condition=0): | |
super().__init__(category, condition) | |
class Clothing(Item): | |
def __init__(self, condition=0): | |
super().__init__(category = "Clothing" , condition) |
class Decor(Item): | ||
def __init__(self, category="Decor", condition=0): | ||
super().__init__(category, condition) |
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.
Same comment from Clothing can be applied here
class Electronics(Item): | ||
def __init__(self, category="Electronics", condition=0): | ||
super().__init__(category, condition) |
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.
Same comment from Clothing can be applied here
def condition_description(self): | ||
if self.condition == 0: | ||
return "This is our lowest rating. This trash won't your treasure, trust us" | ||
elif self.condition == 1: | ||
return "Poor" | ||
elif self.condition == 2: | ||
return "Fair" | ||
elif self.condition == 3: | ||
return "Good" | ||
elif self.condition == 4: | ||
return "Like New" | ||
elif self.condition == 5: | ||
return "This is our highest rating, brand spankin' NEW" |
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.
I like your condition description 😆 Another thing to add to this class is checking if the condition being passed is an integer. Another thing to think about is how would this conditional change if you were using float values instead?
def swap_items(self, Vendor, my_item, their_item): | ||
if (my_item in self.inventory) and (their_item in Vendor.inventory): | ||
self.remove(my_item) | ||
self.add(their_item) | ||
Vendor.add(my_item) | ||
Vendor.remove(their_item) | ||
return True | ||
return False | ||
|
||
def swap_first_item(self, Vendor): | ||
if (self.inventory and Vendor.inventory): | ||
return self.swap_items(Vendor, self.inventory[0], Vendor.inventory[0]) | ||
return False |
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.
Hm... this passed the test however I'd heavily caution in using a Class to add and remove items from. "self" refers to an instance of the Vendor class so when you're adding and removing items from a data structure in the Class itself, you're also affecting the instances. Vendor
should instead be referencing another instance. Book a 1:1 with me anytime you'd like to talk about this (:
list = [] | ||
for item in self.get_by_category(category): | ||
list.append(item.condition) | ||
for item in self.get_by_category(category): | ||
if item.condition == max(list): | ||
return 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.
Because list
is also a function/constructor in Python, I recommend using a different variable name.
def swap_best_by_category(self, other, my_priority, their_priority): | ||
return self.swap_items(other, self.get_best_by_category( | ||
their_priority), other.get_best_by_category(my_priority)) |
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.
Great reuse of methods here
No description provided.