-
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
paper_Manu #70
base: master
Are you sure you want to change the base?
paper_Manu #70
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Clothing", condition) | ||
|
||
def __str__(self): | ||
return("The finest clothing you could wear.") | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Decor", condition) | ||
|
||
def __str__(self): | ||
return("Something to decorate your space.") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Electronics", 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,23 @@ | ||
#wave2 | ||
class Item(): #parens allow inheritance | ||
def __init__(self, category="", condition=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. 👍 |
||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(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. 👍 |
||
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("bad") | ||
if self.condition == 1: | ||
return("very bad") | ||
if self.condition == 2: | ||
return("medium good") | ||
if self.condition == 3: | ||
return("good") | ||
if self.condition == 4: | ||
return("very good") | ||
if self.condition == 5: | ||
return("excellent") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from vendor import Vendor |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
class Vendor(): | ||||||||||||||||||||||||||||||||||||||||||||||
def __init__(self, inventory = False): | ||||||||||||||||||||||||||||||||||||||||||||||
self.inventory = list() | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if inventory: | ||||||||||||||||||||||||||||||||||||||||||||||
self.inventory = inventory | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
def add(self, add_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(add_item) | ||||||||||||||||||||||||||||||||||||||||||||||
return add_item | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
def remove(self, remove_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 remove_item in self.inventory: | ||||||||||||||||||||||||||||||||||||||||||||||
self.inventory.remove(remove_item) | ||||||||||||||||||||||||||||||||||||||||||||||
return remove_item | ||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
#wave2 | ||||||||||||||||||||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||||||||||||||||||||
matching_items = [] | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
for item in self.inventory: | ||||||||||||||||||||||||||||||||||||||||||||||
if item.category == category: | ||||||||||||||||||||||||||||||||||||||||||||||
matching_items.append(item) | ||||||||||||||||||||||||||||||||||||||||||||||
return matching_items | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
#wave3 | ||||||||||||||||||||||||||||||||||||||||||||||
def swap_items(self, friend, 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. 👍 , very readable |
||||||||||||||||||||||||||||||||||||||||||||||
if my_item not in self.inventory or their_item not in friend.inventory: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
self.remove(my_item) | ||||||||||||||||||||||||||||||||||||||||||||||
friend.add(my_item) #add to vendor | ||||||||||||||||||||||||||||||||||||||||||||||
friend.remove(their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
self.add(their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||||||||||||||||||||
#wave4 | ||||||||||||||||||||||||||||||||||||||||||||||
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. 👍 , Just wanted to point out that you can use |
||||||||||||||||||||||||||||||||||||||||||||||
if len(self.inventory) == 0 or len(friend.inventory) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+41
to
+42
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 is a little simpler due to the fact that
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
my_item = self.inventory[0] | ||||||||||||||||||||||||||||||||||||||||||||||
their_item = friend.inventory[0] | ||||||||||||||||||||||||||||||||||||||||||||||
return self.swap_items(friend, my_item, their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
#wave6 | ||||||||||||||||||||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||||||||||||||||||||
items = self.get_by_category(category) | ||||||||||||||||||||||||||||||||||||||||||||||
if len(items) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
best_by_category = items[0] | ||||||||||||||||||||||||||||||||||||||||||||||
for item in items: | ||||||||||||||||||||||||||||||||||||||||||||||
if item.condition > best_by_category.condition: | ||||||||||||||||||||||||||||||||||||||||||||||
best_by_category = item | ||||||||||||||||||||||||||||||||||||||||||||||
return best_by_category | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
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. 👍 |
||||||||||||||||||||||||||||||||||||||||||||||
my_item = self.get_best_by_category(their_priority) | ||||||||||||||||||||||||||||||||||||||||||||||
their_item = other.get_best_by_category(my_priority) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
#DRYup using swap_items | ||||||||||||||||||||||||||||||||||||||||||||||
#return self.swap_items(other, my_item, their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+64
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. This would have been a good choice |
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if my_item and their_item: | ||||||||||||||||||||||||||||||||||||||||||||||
other.remove(their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
self.remove(my_item) | ||||||||||||||||||||||||||||||||||||||||||||||
self.add(their_item) | ||||||||||||||||||||||||||||||||||||||||||||||
other.add(my_item) | ||||||||||||||||||||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# from item import Item | ||||||||||||||||||||||||||||||||||||||||||||||
# item1 = Item("jacket") | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# x = Vendor() | ||||||||||||||||||||||||||||||||||||||||||||||
# print(x.inventory) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# y = Vendor([item1]) | ||||||||||||||||||||||||||||||||||||||||||||||
# print(y.inventory) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# x.add(1) | ||||||||||||||||||||||||||||||||||||||||||||||
# print(x.inventory) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# print (x.remove(3)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# if x.remove(1): | ||||||||||||||||||||||||||||||||||||||||||||||
# print("remove 1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# y.get_by_category("jacket") | ||||||||||||||||||||||||||||||||||||||||||||||
# print(y.get_by_category) | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+82
to
+103
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. Just consider removing the commented code prior to submitting.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
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.
👍 Very clean child classes!