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 - Drew Taylor #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from swap_meet.item import Item


class Clothing(Item):

Choose a reason for hiding this comment

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

👍 perfectly done! this is a great example of inheritance and using the super class


def __init__(self, condition = 0):
super().__init__(category= "Clothing", condition = 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):

Choose a reason for hiding this comment

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

👍


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

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

Choose a reason for hiding this comment

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

👍


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

def __str__(self):
return "A gadget full of buttons and secrets."
21 changes: 21 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Item:

Choose a reason for hiding this comment

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

👍

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

def __str__(self):
return "Hello World!"

def condition_description(self):

Choose a reason for hiding this comment

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

👍

if self.condition == 0:
return "This should have been recycled."
elif self.condition == 1:
return "This is really bad."
elif self.condition == 2:
return "This is in somewhat okay condition."
elif self.condition == 3:
return "This is in decent condition."
elif self.condition == 4:
return "This almost looks new!"
elif self.condition == 5:
return "This looks so new! Very nice."
72 changes: 72 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class Vendor:

Choose a reason for hiding this comment

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

👍

def __init__(self, inventory = None):
if inventory == None:
self.inventory = []
else:
self.inventory = inventory

def add(self, item):

Choose a reason for hiding this comment

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

👍

self.inventory.append(item)
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.

👍

if item in self.inventory:
self.inventory.remove(item)
return item
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.

👍

category_list =[]
for items in self.inventory:
if items.category == category:
category_list.append(items)
return category_list

#Wave 3 *****************************

def swap_items(self, friend_vendor, my_item, their_item):

Choose a reason for hiding this comment

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

👍

if my_item not in self.inventory or their_item not in friend_vendor.inventory:
return False
self.remove(my_item)
friend_vendor.add(my_item)
friend_vendor.remove(their_item)
self.add(their_item)
return True


#Wave 4 **********************************

def swap_first_item(self, friend):

if len(self.inventory) == 0 or len(friend.inventory) == 0:
return False
first_item = self.inventory[0]
self.remove(self.inventory[0])
self.add(friend.inventory[0])
friend.remove(friend.inventory[0])
friend.add(first_item)

return True
Comment on lines +41 to +51

Choose a reason for hiding this comment

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

👍 this works perfectly, but I think we are already doing this on lines 30 - 36. So let's try something like this:

Suggested change
def swap_first_item(self, friend):
if len(self.inventory) == 0 or len(friend.inventory) == 0:
return False
first_item = self.inventory[0]
self.remove(self.inventory[0])
self.add(friend.inventory[0])
friend.remove(friend.inventory[0])
friend.add(first_item)
return True
def swap_first_item(self, friend):
return self.swap_items(friend, self.inventory[0], friend.inventory[0])

we have a method that already swaps items, so we should use it!


#Wave 6 ***************************

def get_best_by_category(self, category):
highest_condition = 0
highest_item = None
for item in self.inventory:
if item.category == category:
if item.condition > highest_condition:
highest_condition = item.condition
highest_item = item
return highest_item
Comment on lines +55 to +63

Choose a reason for hiding this comment

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

👍 this works great! we could also bring in get_by_category method to get all the items of that category then run through them, but your way actually saves you a for loop!

so this is just fine



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.

👍 good job using your other methods to make your code DRY

best_in_my_inventory = self.get_best_by_category(their_priority)
best_item_in_other = other.get_best_by_category(my_priority)
if best_item_in_other == None or best_in_my_inventory == None:
return False
self.swap_items(other, best_in_my_inventory, best_item_in_other)
return True