-
Notifications
You must be signed in to change notification settings - Fork 71
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
swap_meet_Sumitra Chhetri, Scissor class #60
base: master
Are you sure you want to change the base?
Changes from all commits
0592a93
51ce0ac
0902652
e8db509
772f597
ebe7c22
57fe1b8
f022fe5
f55c5b8
25c428b
01cf129
7d86501
5de7749
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from swap_meet.item import Item | ||
|
||
#wave_5 | ||
class Clothing(Item): | ||
""" | ||
inheritance code from method condittion_description | ||
|
||
""" | ||
def __init__(self, category = "Clothing", condition = 0): | ||
self.category = "Clothing" | ||
self.condition = condition | ||
|
||
super().__init__("Clothing", condition) | ||
|
||
def __str__(self): | ||
return ("The finest clothing you could wear.") | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from swap_meet.item import Item | ||
|
||
#wave_5 | ||
class Decor(Item): | ||
""" | ||
inheritance code from method condittion_description | ||
""" | ||
def __init__(self, category = "Decor", condition = 0): | ||
self.category = "Decor" | ||
self.condition = condition | ||
|
||
super().__init__("Decor", condition) | ||
|
||
def __str__(self): | ||
return ("Something to decorate your space.") | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from swap_meet.item import Item | ||
|
||
#wave_5 | ||
class Electronics(Item): | ||
""" | ||
inheritance code from method condittion_description | ||
""" | ||
def __init__(self, category = "Electronics", condition = 0): | ||
self.category = "Electronics" | ||
self.condition = condition | ||
|
||
super().__init__("Electronics", condition) | ||
|
||
def __str__(self): | ||
return ("A gadget full of buttons and secrets.") | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
#wave_2 | ||
class Item(): | ||
def __init__(self, category ="", condition=0): | ||
self.category = category | ||
self.conditon = condition | ||
|
||
#wave_3 | ||
def __str__(self): | ||
return "Hello World!" | ||
|
||
#wave_5 | ||
def condition_description(self): | ||
""" | ||
input: checks the condition of items | ||
output: the condition of items | ||
|
||
""" | ||
if self.conditon <= 1: | ||
return "This is useless and need to recyle." | ||
elif self.conditon <= 2: | ||
return "This looks dirty and whole in them so need to clean and sew them before using." | ||
elif self.conditon <= 3: | ||
return "This is okay but need to clean them." | ||
elif self.conditon <= 4: | ||
return "This is in good condition." | ||
elif self.condition <= 4.9: | ||
return "Basically Brand new." | ||
else: | ||
return "Brand new" |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,112 @@ | ||||||||||||||||||
|
||||||||||||||||||
#wave_1 | ||||||||||||||||||
class Vendor: | ||||||||||||||||||
def __init__(self, inventory = None): | ||||||||||||||||||
if inventory is None: | ||||||||||||||||||
self.inventory = [] | ||||||||||||||||||
else: | ||||||||||||||||||
self.inventory = inventory | ||||||||||||||||||
|
||||||||||||||||||
def adding_to_inventory(Vendor): #checks item in inventory & returns True or False | ||||||||||||||||||
if item in inventory: | ||||||||||||||||||
self.inventory.add(item) | ||||||||||||||||||
else: | ||||||||||||||||||
self.inventory.remove(item) | ||||||||||||||||||
return False | ||||||||||||||||||
|
||||||||||||||||||
def add(self, item): #append item in inventory | ||||||||||||||||||
self.inventory.append(item) | ||||||||||||||||||
return item | ||||||||||||||||||
|
||||||||||||||||||
def remove(self, item): #remove item from inventory | ||||||||||||||||||
if item in self.inventory: | ||||||||||||||||||
self.inventory.remove(item) | ||||||||||||||||||
else: | ||||||||||||||||||
return False | ||||||||||||||||||
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring to address the edge case first:
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
return item | ||||||||||||||||||
|
||||||||||||||||||
#wave_2 | ||||||||||||||||||
def get_by_category(self, category): | ||||||||||||||||||
""" | ||||||||||||||||||
gets items by category | ||||||||||||||||||
input: inventory from items | ||||||||||||||||||
output: list of category | ||||||||||||||||||
|
||||||||||||||||||
""" | ||||||||||||||||||
item_by_category = [] | ||||||||||||||||||
for item in self.inventory: | ||||||||||||||||||
if item.category == category: | ||||||||||||||||||
item_by_category.append(item) | ||||||||||||||||||
return item_by_category | ||||||||||||||||||
|
||||||||||||||||||
#wave_3 | ||||||||||||||||||
def swap_items(self, friend_vendor, my_item, their_item): | ||||||||||||||||||
""" | ||||||||||||||||||
check inventory items of each Vendor | ||||||||||||||||||
input: adds and removes items from each Vendor inventory | ||||||||||||||||||
output: Return True or False | ||||||||||||||||||
""" | ||||||||||||||||||
if my_item in self.inventory and their_item in friend_vendor.inventory: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring to check the edge case first (similar to the comment for |
||||||||||||||||||
self.add(their_item) | ||||||||||||||||||
self.remove(my_item) | ||||||||||||||||||
friend_vendor.add(my_item) | ||||||||||||||||||
friend_vendor.remove(their_item) | ||||||||||||||||||
return True | ||||||||||||||||||
else: | ||||||||||||||||||
return False | ||||||||||||||||||
|
||||||||||||||||||
#wave_4 | ||||||||||||||||||
def swap_first_item(self, friend): | ||||||||||||||||||
""" | ||||||||||||||||||
checks 1st item in self.inventory & friend's inventory | ||||||||||||||||||
input: remove 1st items from self & friend | ||||||||||||||||||
output: adds 1st items to self & friend. Returns True or False | ||||||||||||||||||
""" | ||||||||||||||||||
if self.inventory and friend.inventory: | ||||||||||||||||||
own_item = self.inventory[0] | ||||||||||||||||||
friend_item = friend.inventory[0] | ||||||||||||||||||
|
||||||||||||||||||
self.remove(own_item) | ||||||||||||||||||
friend.add(own_item) | ||||||||||||||||||
friend.remove(friend_item) | ||||||||||||||||||
self.add(friend_item) | ||||||||||||||||||
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can make use of |
||||||||||||||||||
|
||||||||||||||||||
return True | ||||||||||||||||||
else: | ||||||||||||||||||
return False | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
#wave_6 | ||||||||||||||||||
def get_best_by_category(self, category): | ||||||||||||||||||
""" | ||||||||||||||||||
Gets item with the best condition in a certain category | ||||||||||||||||||
input: | ||||||||||||||||||
output: | ||||||||||||||||||
""" | ||||||||||||||||||
category_by_list = self.get_by_category(category) | ||||||||||||||||||
|
||||||||||||||||||
if category_by_list == []: | ||||||||||||||||||
return None | ||||||||||||||||||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider initializing |
||||||||||||||||||
|
||||||||||||||||||
best_item = category_by_list[0] | ||||||||||||||||||
|
||||||||||||||||||
for item in category_by_list: | ||||||||||||||||||
if best_item.condition < item.condition: | ||||||||||||||||||
best_item = item | ||||||||||||||||||
return best_item | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
def swap_best_by_category(self, other, my_priority, their_priority): | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is clear and concise! Great work. |
||||||||||||||||||
""" | ||||||||||||||||||
swaps the best item of certain categories with another vendor | ||||||||||||||||||
input: | ||||||||||||||||||
output: | ||||||||||||||||||
|
||||||||||||||||||
""" | ||||||||||||||||||
my_item = self.get_best_by_category(their_priority) | ||||||||||||||||||
their_item = other.get_best_by_category(my_priority) | ||||||||||||||||||
if my_item == None or their_item == None: | ||||||||||||||||||
return False | ||||||||||||||||||
return self.swap_items(other, my_item, their_item) | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done the same work multiple times, consider refactoring like this: