-
Notifications
You must be signed in to change notification settings - Fork 110
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
Lions - Nancy L #101
base: master
Are you sure you want to change the base?
Lions - Nancy L #101
Changes from all commits
033cdd8
104b63e
caa0b47
648b693
315501c
2711ee7
90d2e38
e003841
7b119e4
2a45a7c
c370c61
07d60bd
1cb7240
31fd0b4
81796f9
4ba9c1c
6195500
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, category="Clothing", condition=0): | ||
super().__init__(category, condition) | ||
|
||
# def __init__(self, category="Clothing", condition=0): | ||
# self.category = category | ||
# self.condition = condition | ||
|
||
def __str__ (self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, category="Decor", condition=0): | ||
super().__init__(category, condition) | ||
|
||
# def __init__(self, category="Decor", condition=0): | ||
# self.category = category | ||
# self.condition = condition | ||
|
||
def __str__ (self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, category="Electronics", condition=0): | ||
super().__init__(category, condition) | ||
|
||
# def __init__(self, category="Electronics", condition=0): | ||
# self.category = category | ||
# self.condition= condition | ||
|
||
def __str__ (self): | ||
return "A gadget full of buttons and secrets." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
|
||
class Item: | ||
pass | ||
def __init__(self, category="", condition=0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__ (self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "poor" | ||
elif self.condition == 1: | ||
return "fair" | ||
elif self.condition == 2: | ||
return "good" | ||
elif self.condition == 3: | ||
return "excellent" | ||
elif self.condition == 4: | ||
return "perfect" | ||
elif self.condition == 5: | ||
return "new" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory=[]): # to set initial attributes | ||
self.inventory = inventory | ||
Comment on lines
+4
to
+5
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. A reminder of the danger of default arguments here. This will cause your integration tests to fail because the list gets re-used. |
||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
if item not in self.inventory: | ||
return False | ||
else: | ||
self.inventory.remove(item) | ||
return item | ||
Comment on lines
+7
to
+16
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. These look great! |
||
|
||
def get_by_category(self, category): | ||
merch =[] | ||
for item in self.inventory: | ||
if item.category == 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. 👍🏻 |
||
merch.append(item) | ||
return merch | ||
|
||
def swap_items(self, friend, my_item, their_item): | ||
if my_item in self.inventory and their_item in friend.inventory: | ||
self.remove(my_item) | ||
friend.add(my_item) | ||
friend.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
|
||
return False | ||
|
||
def swap_first_item(self, friend): | ||
if len(self.inventory) == 0 or len(friend.inventory) == 0: | ||
return False | ||
else: | ||
self.swap_items(friend, my_item=self.inventory[0], their_item=friend.inventory[0]) | ||
return True | ||
Comment on lines
+35
to
+40
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 your helper! |
||
# access self.inventory[0] and friend.inventory[0] | ||
# remove my item from self.inventory and add it to friend.inventory | ||
# remove item from friend.inventory and add it to self.inventory | ||
|
||
def get_best_by_category(self, category): | ||
best_item = None | ||
for item in self.get_by_category(category): | ||
if best_item is None: | ||
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. 👍🏻 |
||
best_item = item | ||
elif item.condition > best_item.condition: | ||
best_item = item | ||
return best_item | ||
|
||
# this function will swap with other, get my priority, get their priority | ||
# def swap_best_by_category(self, other, my_priority, their_priority): | ||
# can use get_best_by_category and swap_first_item (since it's the best by category) | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other.get_best_by_category(my_priority) | ||
if their_best_item is None or my_best_item is None: | ||
return False | ||
else: | ||
self.swap_items(other, my_best_item, their_best_item) | ||
return True | ||
Comment on lines
+58
to
+65
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! Really nice re-use of your earlier methods here. We don't need the 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. Instead of using else I could just use another if statement. Since line 62 returns False, it exits the function. I realized that just now :) |
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 well if the condition is an integer, but what would happen if the condition was a float like
3.5
as it is in some of the tests? Can you think of how you would solve this issue?