From 107630e1656266df1df4c38cc5ca58cfee21d3e7 Mon Sep 17 00:00:00 2001 From: Chris McAnally Date: Tue, 30 Mar 2021 16:04:27 -0700 Subject: [PATCH 1/3] solution --- swap_meet/clothing.py | 11 ++++++++ swap_meet/decor.py | 8 ++++++ swap_meet/electronics.py | 7 +++++ swap_meet/item.py | 8 ++++++ swap_meet/vendor.py | 58 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 swap_meet/clothing.py create mode 100644 swap_meet/decor.py create mode 100644 swap_meet/electronics.py create mode 100644 swap_meet/item.py create mode 100644 swap_meet/vendor.py diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..2c47b5f38 --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,11 @@ + +class Clothing: + def __init__(self, condition=0): + self.category = "Clothing" + self.condition = condition + + def __str__(self): + return "The finest clothing you could wear." + + def __repr__(self): + return f"{self.category} in {self.condition} condition" \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..40acbff2f --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,8 @@ +class Decor: + def __init__(self, condition = 0): + self.category = "Decor" + self.condition = condition + + def __str__(self): + return "Something to decorate your space." + diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py new file mode 100644 index 000000000..0f8373d64 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,7 @@ +class Electronics: + def __init__(self, condition = 0): + self.category = "Electronics" + self.condition = condition + + def __str__(self): + return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..babdbcfd7 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,8 @@ + +class Item: + def __init__(self, category=""): + self.category = category + + + def __str__(self): + return "Hello World!" \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..c54fefac4 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,58 @@ +class Vendor: + + def __init__(self, inventory=[]): + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + try: + self.inventory.remove(item) + return item + except ValueError as ve: + return False + + def get_by_category(self, category): + return [item for item in self.inventory if item.category == category] + + def swap_first_item(self, other_vendor): + if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: + return False + + my_first = self.inventory[0] + other_first = other_vendor.inventory[0] + self.remove(my_first) + other_vendor.remove(other_first) + self.add(other_first) + other_vendor.add(my_first) + return True + + def get_best_by_category(self, category): + inv_by_category = [item for item in self.inventory if item.category == category] + + if len(inv_by_category) == 0: + return None + + print(inv_by_category) + + max = inv_by_category[0] + for item in inv_by_category: + if item.condition > max.condition: + max = item + + return max + + def swap_best_by_category(self, other: 'Vendor', my_priority: str, their_priority: str): + my_best = self.get_best_by_category(their_priority) + their_best = other.get_best_by_category(my_priority) + + if my_best is None or their_best is None: + return False + + self.remove(my_best) + other.remove(their_best) + self.add(their_best) + other.add(my_best) + return True From b18c45a9f637201464ceae4e4821f10c46012e24 Mon Sep 17 00:00:00 2001 From: Chris McAnally Date: Tue, 30 Mar 2021 16:06:19 -0700 Subject: [PATCH 2/3] tests mod --- test.sh | 0 test_vendor.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) mode change 100644 => 100755 test.sh create mode 100644 test_vendor.py diff --git a/test.sh b/test.sh old mode 100644 new mode 100755 diff --git a/test_vendor.py b/test_vendor.py new file mode 100644 index 000000000..7db34bdb2 --- /dev/null +++ b/test_vendor.py @@ -0,0 +1,19 @@ +from swap_meet.vendor import Vendor +from swap_meet.clothing import Clothing +from swap_meet.electronics import Electronics +from swap_meet.decor import Decor + + +item_a = Clothing(condition=2.0) +item_b = Decor(condition=2.0) +item_c = Clothing(condition=4.0) +item_d = Decor(condition=5.0) +item_e = Clothing(condition=3.0) +tai = Vendor( + inventory=[item_a, item_b, item_c, item_d, item_e] +) + +best_item = tai.get_best_by_category("Clothing") + +print(best_item.category) +print(best_item.condition) \ No newline at end of file From a191ee94141bd5e5033eac8c2050db1f353cb6d1 Mon Sep 17 00:00:00 2001 From: Chris McAnally Date: Tue, 30 Mar 2021 16:12:18 -0700 Subject: [PATCH 3/3] remove playground file --- test_vendor.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 test_vendor.py diff --git a/test_vendor.py b/test_vendor.py deleted file mode 100644 index 7db34bdb2..000000000 --- a/test_vendor.py +++ /dev/null @@ -1,19 +0,0 @@ -from swap_meet.vendor import Vendor -from swap_meet.clothing import Clothing -from swap_meet.electronics import Electronics -from swap_meet.decor import Decor - - -item_a = Clothing(condition=2.0) -item_b = Decor(condition=2.0) -item_c = Clothing(condition=4.0) -item_d = Decor(condition=5.0) -item_e = Clothing(condition=3.0) -tai = Vendor( - inventory=[item_a, item_b, item_c, item_d, item_e] -) - -best_item = tai.get_best_by_category("Clothing") - -print(best_item.category) -print(best_item.condition) \ No newline at end of file