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--Andrea Palacios #55

Open
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from swap_meet.item import Item

class Clothing(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!


def __init__(self, condition = 0):
super().__init__(condition, category = 'Clothing')


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__(condition, category = 'Decor')

def __str__(self):
return "Something to decorate your space."

9 changes: 9 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from swap_meet.item import Item


class Electronics(Item):
def __init__(self, condition= 0):
super().__init__(condition, category='Electronics')

def __str__(self):
return "A gadget full of buttons and secrets."
22 changes: 22 additions & 0 deletions swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

class Item:

Choose a reason for hiding this comment

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

👍


def __init__(self, condition= 0, category= ""):
self.category = category
self.condition = condition

def __str__(self):
return "Hello World!"

def condition_description(self):
if self.condition > 4:
return "Excellent Condition!"
elif 3 < self.condition > 4:
return "Barely used!"
elif 1 < self.condition > 3:
return "Needs a little TLC"
else:
return "This item could use A LOT of LOVE."



77 changes: 77 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

class Vendor:

def __init__(self, inventory= None):

Choose a reason for hiding this comment

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

👍

if inventory == None:
self.inventory = []
else:
self.inventory = inventory


def add(self, item):

Choose a reason for hiding this comment

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

👍

self.inventory.append(item)
return item


def remove(self, item):

Choose a reason for hiding this comment

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

👍

if item in self.inventory:
self.inventory.remove(item)
return item
else:
return False
Comment on lines +20 to +21

Choose a reason for hiding this comment

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

You don't need the else:

Suggested change
else:
return False
return False



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.

👍

cat_list = []
for item in self.inventory:
if item.category is category:
cat_list.append(item)
return cat_list
#return [item for item in self.inventory if item.category == category]


def swap_items(self, other, my_item, their_item):
if my_item in self.inventory and their_item in other.inventory:
self.remove(my_item)
other.add(my_item)
self.add(their_item)
other.remove(their_item)
return True
else:
return False
Comment on lines +40 to +41

Choose a reason for hiding this comment

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

Suggested change
else:
return False
return False



def swap_first_item(self, other):

Choose a reason for hiding this comment

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

👍 , just note that you don't need the else:

if len(self.inventory) == 0 or len(other.inventory) == 0:

Choose a reason for hiding this comment

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

You can simplify this a bit.

Suggested change
if len(self.inventory) == 0 or len(other.inventory) == 0:
if not self.inventory or not other.inventory:

return False
else:
my_first_item = self.inventory[0]
their_first_item = other.inventory[0]
self.swap_items(other, my_first_item, their_first_item)
return True


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_list = self.get_by_category(category)
if len(items_list) == 0:
return None

best_condition_item = items_list[0]
for item in items_list:
if item.condition > best_condition_item.condition:
best_condition_item = item
return best_condition_item
#[for item in items_list if item.condition > best_condition_item.condition]


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)

if my_item and their_item:
self.swap_items(other, my_item, their_item)
return True
else:
return False