-
Notifications
You must be signed in to change notification settings - Fork 113
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
Sea Turtles - Shannon B. - swap meet #102
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0.0): | ||
super().__init__(condition=condition, category="Clothing") | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Decor: | ||
pass | ||
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.0): | ||
super().__init__(condition=condition, category="Decor") | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Electronics: | ||
pass | ||
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.0): | ||
super().__init__(condition=condition, category="Electronics") | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
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): | ||
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 making an if/elif statement here. I would look into how you could possibly improve this block of code by using other data structures. |
||
if self.condition <= 1: | ||
return "Belongs in the trash." | ||
elif self.condition <= 2: | ||
return "Oof...bad idea." | ||
elif self.condition <= 3: | ||
return "Is it really worth it?" | ||
elif self.condition <= 4: | ||
return "Heyyyy, this is pretty good~" | ||
elif self.condition <= 5: | ||
return "Brilliant, incredible, amazing, show stopping, spectacular item!" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,62 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
if inventory is None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
Comment on lines
+5
to
+8
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 fun to do it |
||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
items = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
items.append(item) | ||
return items | ||
|
||
def swap_items(self, friend, my_item, their_item): | ||
if my_item in self.inventory and their_item in friend.inventory: | ||
friend.add(my_item) | ||
self.remove(my_item) | ||
self.add(their_item) | ||
friend.remove(their_item) | ||
Comment on lines
+30
to
+33
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 the instance methods you created. |
||
return True | ||
else: | ||
return False | ||
|
||
def swap_first_item(self, friend): | ||
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 here. You could also use try/except in a few places instead of if/else for your error handling. |
||
if not self.inventory or not friend.inventory: | ||
return False | ||
else: | ||
self.swap_items(friend, self.inventory[0], friend.inventory[0]) | ||
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. 👍🏽 |
||
current_best_condition = 0 | ||
best_item = None | ||
if self.get_by_category is None: | ||
return None | ||
for item in self.get_by_category(category): | ||
if item.condition > current_best_condition: | ||
current_best_condition = item.condition | ||
best_item = item | ||
return best_item | ||
|
||
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. 👍🏽 |
||
other_best = other.get_best_by_category(my_priority) | ||
vendor_best = self.get_best_by_category(their_priority) | ||
if not other_best or not vendor_best: | ||
return False | ||
else: | ||
return self.swap_items(other, vendor_best, other_best) |
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.
👍🏽