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

swap_meet #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

swap_meet #74

wants to merge 1 commit into from

Conversation

chanbzz
Copy link

@chanbzz chanbzz commented Apr 8, 2021

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.

great job, Chan! Your code was very easy to read, very simple! My biggest feedback would be on giving Inheritance and super() lessons another read, but other than that you nailed this! :)

Comment on lines +3 to +7
class Clothing(Item):

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

Choose a reason for hiding this comment

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

this works! But since you are using inheritance by importing Item and passing it in, we can take advantage of the parent class's __init__ method that's already been constructed.

Suggested change
class Clothing(Item):
def __init__(self, category = "", condition=0):
self.category = "Clothing"
self.condition = condition
class Clothing(Item):
def __init__(self, condition=0): # because we know Clothing class will always be category "clothing", we don't need to give the user the ability to pass in a value
super().__init__("clothing", condition) # here we are calling the parent class's __init__ method and we pass in the argument from the Child class down to the parent with "clothing". Now we don't need to assign self.category or self.condition again

here's another way we could do it based on Learn's super() lesson:

Suggested change
class Clothing(Item):
def __init__(self, category = "", condition=0):
self.category = "Clothing"
self.condition = condition
class Clothing(Item):
# if we don't change the parameters and keep them exactly like the parent class's __init__ method, then we don't technically have to create a child __init__ method because it will inherit the parent's. So only the __str__ method will be in this class

Both options work, but I would say the top suggestion is better practice, and you will see it in industry

Comment on lines +3 to +10
class Decor(Item):

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

def __str__(self):
return "Something to decorate your space."

Choose a reason for hiding this comment

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

👍 think about what I talked about in clothing.py and apply it here as well!

Comment on lines +3 to +10
class Electronics(Item):

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

def __str__(self):
return "A gadget full of buttons and secrets."

Choose a reason for hiding this comment

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

👍 think about what I talked about in clothing.py and apply it here as well!

Comment on lines +1 to +13
class Item:
def __init__(self, item = "Hello World!", category="", condition = 0):
self.category = category
self.item = item

def __str__(self):
return f"{self.item}"

def __float__(self):
return f"{self.condition}"

def condition_description(self):
return f"{self.condition}"

Choose a reason for hiding this comment

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

looks like self.condition is being used in condition_description method, but it is not assigned in the __init__ method. Let's try something like this:

Suggested change
class Item:
def __init__(self, item = "Hello World!", category="", condition = 0):
self.category = category
self.item = item
def __str__(self):
return f"{self.item}"
def __float__(self):
return f"{self.condition}"
def condition_description(self):
return f"{self.condition}"
class Item:
def __init__(self, category="", condition = 0):
self.category = category
self.condition = condition
def __str__(self):
return "Hello world!"
def condition_description(self):
if self.condition == 0:
return "This item is trash!"
# keep adding all conditions ( 0 thru 5) to this method to give a description to the item, not just the condition number

@@ -0,0 +1,109 @@

class Vendor:

Choose a reason for hiding this comment

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

👍

return item


def remove(self, item):

Choose a reason for hiding this comment

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

👍

else:
return False

def get_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 +45 to +59
def swap_first_item(self, other_vendor):


if self.inventory == [] or other_vendor.inventory == []:

return False

else:

other_vendor.inventory.append(self.inventory[0])
self.inventory.remove(self.inventory[0])
self.inventory.append(other_vendor.inventory[0])
other_vendor.inventory.remove(other_vendor.inventory[0])

return True

Choose a reason for hiding this comment

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

👍 this works perfectly! but let's look at lines 32 - 43 above. We are almost doing the same thing twice, so how could we fix that? We could use the swap_items method inside of this one.

Suggested change
def swap_first_item(self, other_vendor):
if self.inventory == [] or other_vendor.inventory == []:
return False
else:
other_vendor.inventory.append(self.inventory[0])
self.inventory.remove(self.inventory[0])
self.inventory.append(other_vendor.inventory[0])
other_vendor.inventory.remove(other_vendor.inventory[0])
return True
def swap_first_item(self, other_vendor):
return self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0])

So, we call swap_items and pass in the arguments it needs: the other vendor, our item, other vendor's item. So we grab the first item out of the inventories by using index 0. Now we let the method return True or False

Comment on lines +61 to +74
def get_best_by_category(self, category=""):
items_in_category = []

for item in self.inventory:
if item.category == category:
items_in_category.append(item)

best_item = None
best_condition = 0
for item in items_in_category:
if item.condition > best_condition:
best_condition = item.condition
best_item = item
return best_item

Choose a reason for hiding this comment

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

👍 heck yeah this is great! But don't lines 62 - 66 look familiar? I bet we've got a method already built for this!

Suggested change
def get_best_by_category(self, category=""):
items_in_category = []
for item in self.inventory:
if item.category == category:
items_in_category.append(item)
best_item = None
best_condition = 0
for item in items_in_category:
if item.condition > best_condition:
best_condition = item.condition
best_item = item
return best_item
def get_best_by_category(self, category=""):
items_in_category = get_by_category(category)
best_item = None
best_condition = 0
for item in items_in_category:
if item.condition > best_condition:
best_condition = item.condition
best_item = item
return best_item

return best_item


def swap_best_by_category(self, other, my_priority, their_priority):

Choose a reason for hiding this comment

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

👍 beautifully done!!!

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