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

Tigers - Maria and Misha #88

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

Conversation

misha-joy
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job working together, Maria and Misha!

Here are a few things to consider for future projects that I've detailed below in your code:

  • Consider refactoring your child classes, so that they use inheritance. It is an important skill to practice as we move forward.

If you have any questions about the feedback, please reach out to me!


class Clothing(Item):
def __init__(self, category = "Clothing", condition=0):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why aren't we using inheritance for these child classes? The parent class Item already has the ability to construct the attributes category and condition. No reason to reinvent the wheel and do that work over again:

def __init__(self, condition=0):
 super().__init__(category="Clothing", condition=condition)

Let's break this down. super represents our parent class. We call it with () and call the method __init__. Then we pass in the necessary arguments the parent class needs to construct the attributes.

Since we know that Clothing will always have the category "Clothing", let's not give users the opportunity to change that. Remove the category parameter from the child constructor. Now, we as the coder, can always ensure Clothing class will always have a category of "Clothing".

Lastly, based on PEP8 styling guide, "Don’t use spaces around the = sign when used to indicate a keyword argument, or when used to indicate a default value for an unannotated function parameter."

Suggested change
def __init__(self, category = "Clothing", condition=0):
def __init__(self, category="Clothing", condition=0):

source link

Comment on lines 3 to 5
self.category = category
self.condition = condition

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above! Let's use inheritance and remove the spaces around the default parameters

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above! Let's use inheritance

def __init__(self, category = "", condition=0):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, category = "", condition=0):
def __init__(self, category="", condition=0):

def condition_description(self):
rating = self.condition
description = ["very gross", "Not that great", "It's okay...", "gently used", "pretty good", "really great!"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea using a list to find the appropriate description based on the index position!

Comment on lines 33 to 38
self.remove(my_item)
vendor.add(my_item)
vendor.remove(their_item)
self.add(their_item)
return True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above! Let's remove the else and let the main focus of the method stand on its own

return False
else:
self.swap_items(vendor, self.inventory[0], vendor.inventory[0])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job reusing a method!

Here is another option if we want to consider time-space efficiency. swap_meet winds up being O(n) (mostly due to removing the items from the inventory). We could simply swap the items in place here to have O(1) runtime.

 self.inventory[0], vendor.inventory[0] = vendor.inventory[0], self.inventory[0]

More information on swapping values with tuples



def get_best_by_category(self, category):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 67 to 69
self.swap_items(other, my_item_to_swap, others_item_to_swap)
return True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above! Let's remove the else and let the main focus of the method stand on its own



def add(self, added_item):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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.

3 participants