-
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_Karla T_C15 #54
base: master
Are you sure you want to change the base?
Changes from all commits
82f2914
60ace77
f2cff89
de3cdc1
80672ad
634cc3a
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): | ||
pass | ||
def __init__(self,condition = 0.0): | ||
self.category = "Clothing" | ||
self.condition = condition | ||
Comment on lines
+4
to
+6
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. Another way to write this is to use super to take advantage of the code in Item's constructor:
|
||
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): | ||
pass | ||
def __init__(self,condition = 0.0): | ||
self.category = "Decor" | ||
self.condition = condition | ||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from swap_meet.item import Item | ||
class Electronics(Item): | ||
pass | ||
def __init__(self,condition = 0.0): | ||
self.category = "Electronics" | ||
self.condition = 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,23 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category="", condition = 0.0): | ||
self.category = category | ||
self.condition = condition | ||
def __str__(self): | ||
return "Hello World!" | ||
def condition_description(self): | ||
if self.condition == 0: | ||
return "mint condition" | ||
elif self.condition == 1: | ||
return "like new" | ||
elif self.condition == 2: | ||
return "gently used" | ||
elif self.condition == 3: | ||
return "used" | ||
elif self.condition == 4: | ||
return "clean this before using it" | ||
elif self.condition == 5: | ||
return "Please clean 2x over" | ||
Comment on lines
+9
to
+20
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. Condition can have a decimal - what happens if the condition is 3.5? How could you change this section to account for those conditions? |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory = None): | ||
if inventory == None: | ||
self.inventory= [] | ||
else: | ||
self.inventory = inventory | ||
def add(self, add_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. For readability I recommend placing a blank line between the end of one function and the beginning of the next. |
||
self.inventory.append(add_item) | ||
return add_item | ||
def remove(self, remove_item): | ||
if remove_item not in self.inventory: | ||
return False | ||
else: | ||
self.inventory.remove(remove_item) | ||
return remove_item | ||
def get_by_category(self, category): | ||
item_list = [] | ||
for item in self.inventory: | ||
if category == item.category: | ||
item_list.append(item) | ||
return item_list | ||
def swap_items(self, vendor, my_item, their_item): | ||
if my_item not in self.inventory or their_item not in vendor.inventory: | ||
return False | ||
if my_item in self.inventory and their_item in vendor.inventory: | ||
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. The conditional on line 24 will catch the case where an inventory doesn't have the item, so this check isn't needed. If the function gets to this point, each item must be in the correct inventory. |
||
self.remove(my_item) | ||
vendor.add(my_item) | ||
vendor.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
def swap_first_item(self, vendor): | ||
if len(self.inventory) > 0 and len(vendor.inventory) > 0: | ||
my_first_item = self.inventory [0] | ||
their_first_item = vendor.inventory[0] | ||
return self.swap_items(vendor, my_first_item, their_first_item) #adjusted line for "DRY" | ||
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. Excellent code reuse! |
||
|
||
return False | ||
def get_best_by_category(self, category): | ||
items = self.get_by_category(category) | ||
if len(items) == 0: | ||
return None | ||
best_by_category = items[0] | ||
for item in items: | ||
if item.condition > best_by_category.condition: | ||
best_by_category = item | ||
return best_by_category | ||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_item = self.get_best_by_category(their_priority) | ||
their_item = other.get_best_by_category(my_priority) | ||
if my_item and their_item: | ||
return self.swap_items(other, my_item, their_item) #adjusted line for "DRY" | ||
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. Nice! |
||
|
||
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.
pass
is a Python placeholder to avoid syntax errors before code is added. Once code is addedpass
can be removed.