-
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 - Drew Taylor #56
base: master
Are you sure you want to change the base?
Changes from all commits
28864f4
a5bcc7d
6c2d82a
5d00c11
fc30bf0
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__(category= "Clothing", condition = condition) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from swap_meet.item import Item | ||
|
||
class Decor(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): | ||
super().__init__(category= "Decor", condition = 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): | ||
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): | ||
super().__init__(category= "Electronics", 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,21 @@ | ||
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, category = "", condition = 0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
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 self.condition == 0: | ||
return "This should have been recycled." | ||
elif self.condition == 1: | ||
return "This is really bad." | ||
elif self.condition == 2: | ||
return "This is in somewhat okay condition." | ||
elif self.condition == 3: | ||
return "This is in decent condition." | ||
elif self.condition == 4: | ||
return "This almost looks new!" | ||
elif self.condition == 5: | ||
return "This looks so new! Very nice." |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||||||||||||||||||||||||
class Vendor: | ||||||||||||||||||||||||||||
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, inventory = None): | ||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||
category_list =[] | ||||||||||||||||||||||||||||
for items in self.inventory: | ||||||||||||||||||||||||||||
if items.category == category: | ||||||||||||||||||||||||||||
category_list.append(items) | ||||||||||||||||||||||||||||
return category_list | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#Wave 3 ***************************** | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def swap_items(self, friend_vendor, my_item, their_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 my_item not in self.inventory or their_item not in friend_vendor.inventory: | ||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||
self.remove(my_item) | ||||||||||||||||||||||||||||
friend_vendor.add(my_item) | ||||||||||||||||||||||||||||
friend_vendor.remove(their_item) | ||||||||||||||||||||||||||||
self.add(their_item) | ||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#Wave 4 ********************************** | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def swap_first_item(self, friend): | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if len(self.inventory) == 0 or len(friend.inventory) == 0: | ||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||
first_item = self.inventory[0] | ||||||||||||||||||||||||||||
self.remove(self.inventory[0]) | ||||||||||||||||||||||||||||
self.add(friend.inventory[0]) | ||||||||||||||||||||||||||||
friend.remove(friend.inventory[0]) | ||||||||||||||||||||||||||||
friend.add(first_item) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||
Comment on lines
+41
to
+51
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. 👍 this works perfectly, but I think we are already doing this on lines 30 - 36. So let's try something like this:
Suggested change
we have a method that already swaps items, so we should use it! |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#Wave 6 *************************** | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def get_best_by_category(self, category): | ||||||||||||||||||||||||||||
highest_condition = 0 | ||||||||||||||||||||||||||||
highest_item = None | ||||||||||||||||||||||||||||
for item in self.inventory: | ||||||||||||||||||||||||||||
if item.category == category: | ||||||||||||||||||||||||||||
if item.condition > highest_condition: | ||||||||||||||||||||||||||||
highest_condition = item.condition | ||||||||||||||||||||||||||||
highest_item = item | ||||||||||||||||||||||||||||
return highest_item | ||||||||||||||||||||||||||||
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. 👍 this works great! we could also bring in so this is just fine |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
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. 👍 good job using your other methods to make your code DRY |
||||||||||||||||||||||||||||
best_in_my_inventory = self.get_best_by_category(their_priority) | ||||||||||||||||||||||||||||
best_item_in_other = other.get_best_by_category(my_priority) | ||||||||||||||||||||||||||||
if best_item_in_other == None or best_in_my_inventory == None: | ||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||
self.swap_items(other, best_in_my_inventory, best_item_in_other) | ||||||||||||||||||||||||||||
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.
👍 perfectly done! this is a great example of inheritance and using the super class