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 - Dani Sanchez #52

Open
wants to merge 13 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
9 changes: 9 additions & 0 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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 class


def __init__(self, condition = None ):
super().__init__("Clothing", condition)

def __str__(self):
return "The finest clothing you could wear."
11 changes: 11 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from swap_meet.item import Item

class Decor(Item):


def __init__(self, condition = None):
super().__init__("Decor", condition)


def __str__(self):
return "Something to decorate your space."
11 changes: 11 additions & 0 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from swap_meet.item import Item

class Electronics(Item):


def __init__(self, condition = None):
super().__init__("Electronics", condition)


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


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, category = None, condition = None):
if category:
self.category = category
else:
self.category = ""

if condition:
self.condition = float(condition)
else:
self.condition = 0


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



def condition_description(self):
if self.condition > 4.0 :
return "super duper best condition"
elif self.condition > 3.0 :
return "pretty alright!"
elif self.condition > 2.0 :
return "Has seen better days"
elif self.condition > 1.0 :
return "maybe wash it once you get home"
elif self.condition >= 0.0 :
return "pretty terrible!!!"
65 changes: 65 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@


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:
self.inventory = inventory
else:
self.inventory = []

def add(self, new_item):
self.inventory.append(new_item)
return new_item

#removes item_to_remove from self's inventory
def remove(self, item_to_remove):

Choose a reason for hiding this comment

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

👍

for item in self.inventory:
if item == item_to_remove:
self.inventory.remove(item_to_remove)
return item_to_remove
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.

👍

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

def swap_items(self, vendor_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.

👍

if self.remove(my_item):
if vendor_friend.remove(their_item):
vendor_friend.add(my_item)
self.add(their_item)
return True
else:
self.add(my_item)
return False


def swap_first_item(self, vendor_friend):
if len(self.inventory) != 0 and len(vendor_friend.inventory) != 0:

Choose a reason for hiding this comment

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

This type of thing can be simplified a bit because [] is falsey.

Suggested change
if len(self.inventory) != 0 and len(vendor_friend.inventory) != 0:
if not self.inventory and not vendor_friend.inventory:

self.swap_items(vendor_friend, self.inventory[0], vendor_friend.inventory[0])
return True
return False

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.

👍

category_list = self.get_by_category(category)
if len(category_list) >= 1:
best_condition_item = category_list[0]
for item in category_list:
if item.condition > best_condition_item.condition:
best_condition_item = item
return best_condition_item
return None

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_best_item = self.get_best_by_category(their_priority)
their_best_item = other.get_best_by_category(my_priority)
if my_best_item and their_best_item:
self.swap_items(other, my_best_item, their_best_item)
return True
return False