Skip to content
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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Rock-lin #58

wants to merge 14 commits into from

Conversation

lzhang39
Copy link

@lzhang39 lzhang39 commented Apr 7, 2021

No description provided.

Copy link

@audreyandoy audreyandoy left a 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! 🥳

Comment on lines +4 to +6
class Clothing(Item):
def __init__(self, category="Clothing", condition=0):
super().__init__(category, condition)

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!

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.

Suggested change
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)

Comment on lines +4 to +6
class Decor(Item):
def __init__(self, category="Decor", condition=0):
super().__init__(category, condition)

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

Comment on lines +4 to +6
class Electronics(Item):
def __init__(self, category="Electronics", condition=0):
super().__init__(category, condition)

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

Comment on lines +18 to +30
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"

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?

Comment on lines +28 to +40
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

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

Comment on lines +43 to +48
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

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.

Comment on lines +50 to +52
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))

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

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