Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from swap_meet.item import Item

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Very clean child classes!


class Clothing(Item):
def __init__(self, condition=0):
super().__init__("Clothing", condition)

def __str__(self):
return("The finest clothing you could wear.")



10 changes: 10 additions & 0 deletions swap_meet/decor.py
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.")


10 changes: 10 additions & 0 deletions swap_meet/electronics.py
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.")


23 changes: 23 additions & 0 deletions swap_meet/item.py
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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

self.category = category
self.condition = condition

def __str__(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return("Hello World!")

def condition_description(self):

Choose a reason for hiding this comment

The 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")

1 change: 1 addition & 0 deletions swap_meet/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from vendor import Vendor
106 changes: 106 additions & 0 deletions swap_meet/vendor.py
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):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , Just wanted to point out that you can use swap_item in the swap_first_item function.

if len(self.inventory) == 0 or len(friend.inventory) == 0:
return False
Comment on lines +41 to +42

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little simpler due to the fact that [] is falsey.

Suggested change
if len(self.inventory) == 0 or len(friend.inventory) == 0:
return False
if not self.inventory or not friend.inventory:
return False


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):

Choose a reason for hiding this comment

The 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):

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just consider removing the commented code prior to submitting.

Suggested change
# 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)