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

Whales - K Frank #111

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Whales - K Frank #111

wants to merge 10 commits into from

Conversation

kirfran
Copy link

@kirfran kirfran commented Apr 13, 2022

No description provided.

Copy link

@alope107 alope107 left a comment

Choose a reason for hiding this comment

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

Great job K! Very nice use of inheritance and re-use of methods. You've written some really DRY code here! This submission is green~

Comment on lines +2 to +4
def __init__(self, category = "Clothing", condition = 0):
super().__init__(category, condition)

Choose a reason for hiding this comment

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

Great use of super here! Consider removing the category from the constructor arguments on line 3. We know we always want it to be "Clothing" so we don't want to allow changing it when instantiating an instance.

Comment on lines +3 to +4
def __init__(self, category = "Electronics", condition = 0):
super().__init__(category, condition)

Choose a reason for hiding this comment

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

Tiny style point here and elsewhere: when defining default arguments don't include spaces on either side of the equals sign. We would instead write it like:

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

Comment on lines +9 to +21
if self.condition == 0:
return "Poor"
if self.condition == 1:
return "Fair"
if self.condition == 2:
return "Good"
if self.condition == 3:
return "Very good"
if self.condition == 4:
return "Like new"
if self.condition ==5:
return "New"

Choose a reason for hiding this comment

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

Great job having this be defined here once and inherited by the child classes!

Comment on lines +9 to +12
'''Adds an item to a vendor's inventory'''
self.inventory.append(item)
return item

Choose a reason for hiding this comment

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

Great docstrings here and elsewhere!

Comment on lines +4 to +7
if not inventory:
inventory = []
self.inventory = inventory

Choose a reason for hiding this comment

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

Nice job avoiding a mutable default object.

Comment on lines +21 to +24
"Returns a list of items of a category in a vendor's inventory"
item_list = [item for item in self.inventory if item.category == category]
return item_list

Choose a reason for hiding this comment

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

Great comprehension!

Comment on lines +36 to +39
'''Swaps the first item in two vendor inventories (self and vendor)'''
if self.inventory and vendor.inventory:
return self.swap_items(vendor, self.inventory[0], vendor.inventory[0])

Choose a reason for hiding this comment

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

Love how you re-use your earlier method! One small bug here: according to the README this method should return False if either of the inventories is empty, but it actually returns None.

Comment on lines +41 to +50
'''Returns the best item in vendor inventory by category. If multiple items, returns the item with the highest condition'''
items_list = self.get_by_category(category)
if not items_list:
return None
best_item = items_list[0]
for item in items_list:
if item.condition > best_item.condition:
best_item = item
return best_item

Choose a reason for hiding this comment

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

Great logic and re-use of method here!

Comment on lines +52 to +53
assert result == "c"
assert vendor.inventory == ["a", "b"]

Choose a reason for hiding this comment

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

Nice asserts!

Comment on lines +205 to +206
# - That the results is truthy
assert not result

Choose a reason for hiding this comment

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

Looks like you may have accidentally copied a comment that says the opposite of what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants