-
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
Paper--Andrea Palacios #55
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,10 @@ | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
|
||
def __init__(self, condition = 0): | ||
super().__init__(condition, category = 'Clothing') | ||
|
||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
|
||
def __init__(self, condition = 0): | ||
super().__init__(condition, category = 'Decor') | ||
|
||
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__(condition, category='Electronics') | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
class Item: | ||
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. 👍 |
||
|
||
def __init__(self, condition= 0, category= ""): | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition > 4: | ||
return "Excellent Condition!" | ||
elif 3 < self.condition > 4: | ||
return "Barely used!" | ||
elif 1 < self.condition > 3: | ||
return "Needs a little TLC" | ||
else: | ||
return "This item could use A LOT of LOVE." | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||||
|
||||||||
class Vendor: | ||||||||
|
||||||||
def __init__(self, inventory= None): | ||||||||
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. 👍 |
||||||||
if inventory == None: | ||||||||
self.inventory = [] | ||||||||
else: | ||||||||
self.inventory = inventory | ||||||||
|
||||||||
|
||||||||
def add(self, item): | ||||||||
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. 👍 |
||||||||
self.inventory.append(item) | ||||||||
return item | ||||||||
|
||||||||
|
||||||||
def remove(self, item): | ||||||||
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. 👍 |
||||||||
if item in self.inventory: | ||||||||
self.inventory.remove(item) | ||||||||
return item | ||||||||
else: | ||||||||
return False | ||||||||
Comment on lines
+20
to
+21
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. You don't need the
Suggested change
|
||||||||
|
||||||||
|
||||||||
def get_by_category(self, category): | ||||||||
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. 👍 |
||||||||
cat_list = [] | ||||||||
for item in self.inventory: | ||||||||
if item.category is category: | ||||||||
cat_list.append(item) | ||||||||
return cat_list | ||||||||
#return [item for item in self.inventory if item.category == category] | ||||||||
|
||||||||
|
||||||||
def swap_items(self, other, my_item, their_item): | ||||||||
if my_item in self.inventory and their_item in other.inventory: | ||||||||
self.remove(my_item) | ||||||||
other.add(my_item) | ||||||||
self.add(their_item) | ||||||||
other.remove(their_item) | ||||||||
return True | ||||||||
else: | ||||||||
return False | ||||||||
Comment on lines
+40
to
+41
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.
Suggested change
|
||||||||
|
||||||||
|
||||||||
def swap_first_item(self, other): | ||||||||
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. 👍 , just note that you don't need the |
||||||||
if len(self.inventory) == 0 or len(other.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. You can simplify this a bit.
Suggested change
|
||||||||
return False | ||||||||
else: | ||||||||
my_first_item = self.inventory[0] | ||||||||
their_first_item = other.inventory[0] | ||||||||
self.swap_items(other, my_first_item, their_first_item) | ||||||||
return True | ||||||||
|
||||||||
|
||||||||
def get_best_by_category(self, category): | ||||||||
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. 👍 |
||||||||
items_list = self.get_by_category(category) | ||||||||
if len(items_list) == 0: | ||||||||
return None | ||||||||
|
||||||||
best_condition_item = items_list[0] | ||||||||
for item in items_list: | ||||||||
if item.condition > best_condition_item.condition: | ||||||||
best_condition_item = item | ||||||||
return best_condition_item | ||||||||
#[for item in items_list if item.condition > best_condition_item.condition] | ||||||||
|
||||||||
|
||||||||
def swap_best_by_category(self, other, my_priority, their_priority): | ||||||||
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. 👍 |
||||||||
my_item = self.get_best_by_category(their_priority) | ||||||||
their_item = other.get_best_by_category(my_priority) | ||||||||
|
||||||||
if my_item and their_item: | ||||||||
self.swap_items(other, my_item, their_item) | ||||||||
return True | ||||||||
else: | ||||||||
return False | ||||||||
|
||||||||
|
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.
Very clean child classes!