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
9 changes: 9 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item


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

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)


def __str__(self):
return "The finest clothing you could wear."
9 changes: 9 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item


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

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 __str__(self):
return "Something to decorate your space."
9 changes: 9 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item


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

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 __str__(self):
return "A gadget full of buttons and secrets."
30 changes: 30 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# from swap_meet.vendor import Vendor

# ***WAVE 1/5***
class Item:
def __init__(self, category=None, condition=0):
self.category = category
self.condition = condition
if category == None:
self.category = ""
else:
self.category = category

# ***WAVE 3***
def __str__(self):
return "Hello World!"

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

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?

52 changes: 52 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Vendor:
def __init__(self, inventory=None):
self.inventory = inventory
if inventory == None:
self.inventory = []
else:
self.inventory = inventory

def add(self, item):
self.item = item
self.inventory.append(item)
return item

def remove(self, item):
self.item = item
if item in self.inventory:
self.inventory.remove(item)
return item
return False

def get_by_category(self, category):
items_matching_category = []
for item in self.inventory:
if category == item.category:
items_matching_category.append(item)
return items_matching_category

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

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


def get_best_by_category(self, category):
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
Comment on lines +43 to +48

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

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