-
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?
Conversation
…ap_first_item by making use of swap_items method.
@@ -0,0 +1,9 @@ | |||
from swap_meet.item import Item | |||
class Clothing(Item): | |||
pass |
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 added pass
can be removed.
def __init__(self,condition = 0.0): | ||
self.category = "Clothing" | ||
self.condition = condition |
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.
Another way to write this is to use super to take advantage of the code in Item's constructor:
def __init__(self, condition = 0.0):
super().__init__("Clothing", condition)
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" |
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.
Condition can have a decimal - what happens if the condition is 3.5? How could you change this section to account for those conditions?
self.inventory= [] | ||
else: | ||
self.inventory = inventory | ||
def add(self, add_item): |
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.
For readability I recommend placing a blank line between the end of one function and the beginning of the next.
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 comment
The 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent code reuse!
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Great work on this project! Your use of helper functions in Vender is excellent. I have a few stylistic comments to improve readability, but overall this is a very solid project. |
No description provided.