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 - Maria M. #53

Open
wants to merge 4 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 @@
#Wave 5

from swap_meet.item import Item

class Clothing(Item):

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

def __str__(self):
return "The finest clothing you could wear."
12 changes: 12 additions & 0 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Wave 5

from swap_meet.item import Item

class Decor(Item):

def __init__(self, condition=0):
Item.__init__(self, "Decor", 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 @@
#Wave 5

from swap_meet.item import Item

class Electronics(Item):

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

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 @@
#Wave 2
class Item:
def __init__(self, category = "", condition=0,):
self.category = category
self.condition = condition

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

#Wave 5
def condition_description(self):
condition = self.condition
if condition >= 4.0:
return (f"The condition rating of this item is a {condition}, it's almost new")
elif condition >= 3.0:
return (f"The condition rating of this item is a {condition}, it's in good condition and gently used.")
elif condition >= 2.0:
return (f"The condition rating of this item is a {condition}, it's in fair condition and has cosmetic flaws and signs of use.")
else:
return (f"The condition rating of this item is a {condition}, it's in poor condition and has some major cosmetic flaws.")


79 changes: 79 additions & 0 deletions swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from swap_meet.item import Item
from swap_meet.clothing import Clothing
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

#Wave 1
class Vendor:
def __init__(self, inventory = None):
if inventory is None:
self.inventory = []
else:
self.inventory = inventory

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

def remove(self, remove_item):
if remove_item not in self.inventory:
return False
else:
self.inventory.remove(remove_item)
return remove_item

#Wave 2
def get_by_category(self, category):
category_list = []
for item in self.inventory:
if item.category == category:
category_list.append(item)
return category_list

#Wave 3
def swap_items(self, friend, my_item, their_item):
if my_item not in self.inventory or \
their_item not in friend.inventory:
return False

self.remove(my_item)
friend.add(my_item)
friend.remove(their_item)
self.add(their_item)
Comment on lines +39 to +42

Choose a reason for hiding this comment

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

Great use of existing methods!

return True

#Wave 4
def swap_first_item(self, friend):
if len(self.inventory) < 1 or \
len(friend.inventory) < 1:
return False

my_first_item = self.inventory[0]
their_first_item = friend.inventory[0]

self.swap_items(friend, my_first_item, their_first_item)

Choose a reason for hiding this comment

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

Great use of the existing method!

return True


#Wave 6
def get_best_by_category(self, category):
best_item = None
best_item_condition = -1
for item in self.inventory:
if item.category == category:
if item.condition > best_item_condition:
best_item = item
best_item_condition = item.condition
return best_item

def swap_best_by_category(self, other, my_priority, their_priority):

my_best_item = self.get_best_by_category(their_priority)

Choose a reason for hiding this comment

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

Great use of the existing method!

if my_best_item == None:
return False

their_best_item = other.get_best_by_category(my_priority)
if their_best_item == None:
return False

return self.swap_items(other, my_best_item, their_best_item)