-
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 - Priscille #50
base: master
Are you sure you want to change the base?
Rock - Priscille #50
Conversation
… swap the best item by category.
def __init__(self, category="Clothing", condition=0, age=0): | ||
super().__init__(category, condition, age) |
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 works perfectly! But it still lets the user change the category, and we don't want that. class Clothing will always have the category "clothing." So let's try this:
def __init__(self, category="Clothing", condition=0, age=0): | |
super().__init__(category, condition, age) | |
def __init__(self, condition=0, age=0): | |
super().__init__("clothing", condition, age) |
@@ -0,0 +1,10 @@ | |||
from swap_meet.item import Item | |||
|
|||
class Decor(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.
👍 We can do the same thing here as we did above!
@@ -0,0 +1,10 @@ | |||
from swap_meet.item import Item | |||
|
|||
class Electronics(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.
👍 We can do the same thing here as we did above!
def __init__(self, category = "", condition = 0, age = 0): | ||
if category is None: | ||
self.category = "" | ||
else: | ||
self.category = category | ||
if condition is None: | ||
self.condition = 0 | ||
else: | ||
self.condition = condition | ||
if age is None: | ||
self.age = 0 | ||
else: | ||
self.age = age |
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 works good! But our default parameters, like category=""
already do what the if-else statements do. so let's let the default parameters do all the work.
def __init__(self, category = "", condition = 0, age = 0): | |
if category is None: | |
self.category = "" | |
else: | |
self.category = category | |
if condition is None: | |
self.condition = 0 | |
else: | |
self.condition = condition | |
if age is None: | |
self.age = 0 | |
else: | |
self.age = age | |
def __init__(self, category = "", condition = 0, age = 0): | |
self.category = category | |
self.condition = condition | |
self.age = age |
now category will be assigned ""
if the user doesn't add in an argument. It will do what if-else statements are doing for us!
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): |
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.
👍
item_a = self.inventory[0] | ||
item_d = vendor_friend.inventory[0] | ||
result = self.swap_items(vendor_friend, item_a, item_d) |
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.
we could get rid of these two variables if we wanted!
item_a = self.inventory[0] | |
item_d = vendor_friend.inventory[0] | |
result = self.swap_items(vendor_friend, item_a, item_d) | |
result = self.swap_items(vendor_friend, self.inventory[0], vendor_friend.inventory[0]) |
result = self.swap_items(vendor_friend, item_a, item_d) | ||
return result | ||
|
||
def get_best_by_category(self, category_name): |
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.
👍
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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
# Optional Enhancements: item by age | ||
|
||
def get_newest_item(self): |
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.
👍
newest_item = item | ||
return newest_item | ||
|
||
def swap_by_newest(self, business_partner, my_newest_item, their_newest_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.
👍
No description provided.