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

Scissors, Mai Truong #49

Open
wants to merge 5 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


class Clothing(Item):
def __init__(self, category = "Clothing", condition = 0):
self.category = category
self.condition = 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, category = "Decor", condition = 0):
self.category = category
self.condition = 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, category = "Electronics", condition = 0):
self.category = category
self.condition = 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 @@
class Item:
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.0:
return "Are you sure you want that?"
elif self.condition <= 1.0:
return "Came from home with 8 kids & 3 mastiffs."
elif self.condition <= 2.0:
return "Could be worse?"
elif self.condition <= 3.0:
return "Meh..."
elif self.condition <= 4.0:
return "One heck of a deal!"
else:
return "If you don't take, it's coming home to mama."
Comment on lines +11 to +22

Choose a reason for hiding this comment

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

Love these 😆


78 changes: 78 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class Vendor:
def __init__(self, inventory = None):
if inventory == None:
self.inventory = []
else:
self.inventory = inventory


def add(self, item):

self.inventory.append(item)
return item


def remove(self, item):

if item in self.inventory:
self.inventory.remove(item)
return item
else:
return False

def get_by_category(self, category):

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


def swap_items(self, vendor_friend, my_item, their_item):

if my_item not in self.inventory or their_item not in vendor_friend.inventory:
return False
else:
self.remove(my_item)
vendor_friend.add(my_item)
vendor_friend.remove(their_item)
self.add(their_item)
return True


def swap_first_item(self, vendor_friend):

if self.inventory and vendor_friend.inventory:
my_item = self.inventory[0]
their_item = vendor_friend.inventory[0]
self.swap_items(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.

Great use of existing method!

return True
else:
return False

def get_best_by_category(self, category):

list_of_items = self.get_by_category(category)

Choose a reason for hiding this comment

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

Great use of existing method!


for item in list_of_items:
if list_of_items == []:
return None

best_condition = 0.0
for item in list_of_items:
if item.condition > best_condition:
best_condition = item.condition
for item in list_of_items:
if best_condition == item.condition:
return item

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 == None or my_best_item == None:
return False
else:
return self.swap_items(other, my_best_item, their_best_item)
Comment on lines +70 to +78

Choose a reason for hiding this comment

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

So clean!