-
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
Rock - Abigail C. #65
base: master
Are you sure you want to change the base?
Changes from all commits
0ec0414
f23c132
a6f9044
9fd6311
1ad1d28
20aeddb
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,12 @@ | ||||||||
|
||||||||
from swap_meet.item import Item | ||||||||
class Clothing(Item): | ||||||||
def __init__(self, category = "", condition = 0): | ||||||||
self.category = "Clothing" | ||||||||
self.condition = condition | ||||||||
Comment on lines
+5
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. The two lines can be reduced to
Suggested change
|
||||||||
|
||||||||
def __str__(self): | ||||||||
''' | ||||||||
reassigns the stringified item | ||||||||
''' | ||||||||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, category = "", condition = 0): | ||
self.category = "Decor" | ||
self.condition = condition | ||
Comment on lines
+6
to
+7
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. Same recommendation as above to use |
||
|
||
def __str__(self): | ||
''' | ||
reassigns the stringified item | ||
''' | ||
return "Something to decorate your space." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, category = "", condition = 0): | ||
self.category = "Electronics" | ||
self.condition = condition | ||
Comment on lines
+6
to
+7
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. Beating a dead horse but same as above about |
||
|
||
def __str__(self): | ||
''' | ||
reassigns the stringified item | ||
''' | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Item: | ||
def __init__(self, category = "", condition = 0): | ||
if category == None: | ||
self.category = "" | ||
else: | ||
self.category = category | ||
self.condition = condition | ||
Comment on lines
+6
to
+7
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. Is condition always going to be an integer? A way to make your code more robust is to also check if condition is the correct data type you're expecting. What about float values or strings? |
||
|
||
def __str__(self): | ||
''' | ||
reassigns the stringified item | ||
''' | ||
return "Hello World!" | ||
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! 👍 |
||
|
||
def condition_description(self): | ||
''' | ||
based on the condition number outputs | ||
the appropriate condition description for the item. | ||
''' | ||
if self.condition == 5: | ||
five_condition_description = "Great Condition" | ||
return five_condition_description | ||
elif self.condition == 4: | ||
four_condition_description = "Good Condition" | ||
return one_condition_description | ||
elif self.condition == 3: | ||
three_condition_description = "Okay Condition" | ||
return one_condition_description | ||
elif self.condition == 2: | ||
two_condition_description = "Poor Condition" | ||
return one_condition_description | ||
elif self.condition == 1: | ||
one_condition_description = "Very Poor Condition" | ||
return one_condition_description | ||
Comment on lines
+20
to
+34
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. One good thought exercise is how mighty our conditionals change if condition was a float? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
def __init__(self, inventory = None): | ||
if inventory == None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
''' | ||
Input: an item | ||
Output: the Input item that was added to the inventory | ||
''' | ||
result = self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
''' | ||
Input: an item | ||
Output: Either the the Input item that was | ||
removed from the inventory or False | ||
''' | ||
if item in self.inventory: | ||
result = self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
''' | ||
Input: a category used to help get an item by category | ||
Output: a list of items within the same category | ||
''' | ||
item_list = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
item_list.append(item) | ||
return item_list | ||
|
||
def swap_items(self, other_vendor, vendor_item, other_vendor_item): | ||
''' | ||
Input: the vendor to swap with, | ||
the orginal vendor's item and the other vendor's item | ||
|
||
Output: Returns False if the items are not in either vendors inventory. | ||
If if both items are avialble the code returns True and switches | ||
other_vendor_item with vendor_item and vis versa. | ||
Also removes the items switched from each inventory. | ||
''' | ||
if (vendor_item not in self.inventory or | ||
other_vendor_item not in other_vendor.inventory): | ||
return False | ||
else: | ||
for item in other_vendor.inventory: | ||
if item == other_vendor_item: | ||
self.inventory.append(item) | ||
other_vendor.inventory.remove(item) | ||
for item in self.inventory: | ||
if item == vendor_item: | ||
other_vendor.inventory.append(item) | ||
self.inventory.remove(item) | ||
return True | ||
Comment on lines
+55
to
+63
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! 👍 |
||
|
||
def swap_first_item(self, other_vendor): | ||
''' | ||
Input: the vendor to swap with. | ||
Output: Returns False if either the vendor or other_vendor | ||
inventory is an empty list. If neither are empty lists the code | ||
implements the swap.item method to swap the first item of each | ||
inventory with the other and removes the items from their orginal lists. | ||
''' | ||
if self.inventory == [] or other_vendor.inventory == []: | ||
return False | ||
else: | ||
self.swap_items(other_vendor,self.inventory[0],other_vendor.inventory[0]) | ||
return True | ||
|
||
def get_best_by_category(self, category): | ||
''' | ||
Input: the category to filer by. | ||
Output: Returns the item with the largest condition | ||
and that matches the same type of category as the input. | ||
''' | ||
largest_num = 0 | ||
largest_item = None | ||
for item in self.inventory: | ||
if category == item.category: | ||
if item.condition > largest_num: | ||
largest_num = item.condition | ||
largest_item = item | ||
return largest_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. Great job! 👍 |
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
''' | ||
Input: the vendor to swap with, | ||
the orginal vendor's item and the other vendor's item | ||
|
||
Output: Returns False if either vendor or other's inventory are empty lists. | ||
If both inventories are not empty lists the code returns True and uses the method | ||
get_best_category and the approprate argument to find the best condition. | ||
The code and uses the method swap_item to swap my_priority and their_priority. | ||
''' | ||
if self.inventory == [] or other.inventory == []: | ||
return False | ||
else: | ||
vendor_item = other.get_best_by_category(my_priority) | ||
other_item = self.get_best_by_category(their_priority) | ||
self.swap_items(other, other_item, vendor_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. great use of other methods! |
||
return True |
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.
This looks great! You can further refactor this by using
super()
to inherit the category and condition attributes since Clothing is a child class.