-
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
Otters_C17 - Doina's Swap-Meet Project #87
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,12 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0): | ||
super().__init__(condition=condition) | ||
self.category = "Clothing" | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
||
def condition_description(self): | ||
return str(self.condition) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition=0): | ||
super().__init__(condition=condition) | ||
self.category = "Decor" | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition=0): | ||
super().__init__(condition=condition) | ||
self.category = "Electronics" | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
||
def condition_description(self): | ||
return str(self.condition) | ||
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. note about method overriding applies here too |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
class Item: | ||
pass | ||
category = "" | ||
condition = 0 | ||
|
||
def __init__(self, **kwargs): | ||
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. Ooo! Super cool that you're using |
||
if 'category' in kwargs: | ||
self.category = kwargs['category'] | ||
|
||
if 'condition' in kwargs: | ||
self.condition = kwargs['condition'] | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
return str(self.condition) | ||
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. Be sure to read the requirements carefully! This function is supposed to return different descriptions based on the condition ranging from 0 to 5. (Wave 5) also (small note), make sure to have a blank line at the end of your Python files. It's convention. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,76 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
if inventory is None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
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, other_vendor, my_item, their_item): | ||
if not (my_item in self.inventory and their_item in other_vendor.inventory): | ||
return False | ||
|
||
self.inventory.remove(my_item) | ||
other_vendor.inventory.append(my_item) | ||
other_vendor.inventory.remove(their_item) | ||
self.inventory.append(their_item) | ||
|
||
return True | ||
|
||
def swap_first_item(self, other_vendor): | ||
if self.inventory == [] or other_vendor.inventory == []: | ||
return False | ||
|
||
tmp = self.inventory[0] | ||
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. Small note - you could reuse the |
||
self.inventory[0] = other_vendor.inventory[0] | ||
other_vendor.inventory[0] = tmp | ||
|
||
return True | ||
|
||
def get_best_by_category(self, category): | ||
best_item = None | ||
for item in self.inventory: | ||
if item.category == category: | ||
if best_item is None or item.condition > best_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. Beautiful solution ✨ |
||
best_item1 = self.get_best_by_category(their_priority) | ||
print(best_item1) | ||
best_item2 = other.get_best_by_category(my_priority) | ||
|
||
return self.swap_items(other, best_item1, best_item2) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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.
Your
Clothing
class is inheriting fromItem
which means it automatically has thecondition_description()
method defined inItem
, so you don't need to redefine the method in the child class. You only need to redefine the method in the child class when you want it to behave differently than the parent class's version which is called method overriding.