-
Notifications
You must be signed in to change notification settings - Fork 71
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
Scissors Laurel O #57
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, condition=0): | ||
super().__init__("Clothing", condition) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Decor", condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
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, condition=0): | ||
super().__init__("Electronics", condition) | ||
|
||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 < 1: | ||
return "I would be cautious handling this, it's really old." | ||
elif self.condition < 2: | ||
return "Probably has some use still left?" | ||
elif self.condition < 3: | ||
return "Doesn't look like much but it will get the job done." | ||
elif self.condition < 4: | ||
return "This has a lot of use left!" | ||
elif self.condition < 5: | ||
return "Really good condition!" | ||
else: | ||
return "It's perfect, never used, still in orginal packaging." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Vendor: | ||
def __init__(self, inventory = None): | ||
if inventory == None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
matched = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
matched.append(item) | ||
return matched | ||
|
||
def swap_items(self, them, my_item, their_item): | ||
if their_item not in them.inventory or my_item not in self.inventory: | ||
return False | ||
else: | ||
self.inventory.remove(my_item) | ||
them.inventory.append(my_item) | ||
them.inventory.remove(their_item) | ||
self.inventory.append(their_item) | ||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the Vendor add & remove functions here. |
||
return True | ||
|
||
def swap_first_item(self, them): | ||
if len(self.inventory) == 0 or len(them.inventory) == 0: | ||
return False | ||
return self.swap_items(them, self.inventory[0], them.inventory[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great code re-use! |
||
|
||
def get_best_by_category(self, category): | ||
items_in_category = self.get_by_category(category) | ||
if len(items_in_category) > 0: | ||
#lambda lets me define a func in a single line | ||
return max(items_in_category, key = lambda item: item.condition) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat solution! I appreciate seeing all of the different versions in your commit history. |
||
else: | ||
return None | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_category = self.get_best_by_category(their_priority) | ||
their_category = other.get_best_by_category(my_priority) | ||
total = self.swap_items(other, my_category, their_category) | ||
return total |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of super()!