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

Amber Tanaka: Orca Whale #105

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

Conversation

AmberRose2
Copy link

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.

This looks great! Nice logic and nice use of inheritance! This project is definitely green~

Comment on lines +3 to +6
def __init__ (self, category=str(), condition = 0):
self.category = "Clothing"
self.condition = condition

Choose a reason for hiding this comment

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

Here and in the other Item subclasses, the category=str() is not needed. You hardcode the category to "Clothing" on line 5, so the category that gets passed in as an argument is ignored, and thus unneeded.

Also, consider using super instead of copying the logic to set the category and condition. Even though it doesn't save you much here, it makes your code easier to extend if you ever add more complex logic to the Item constructor.

Comment on lines +8 to +9
return "The finest clothing you could wear."

Choose a reason for hiding this comment

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

Nice override of __str__!

Comment on lines +9 to +21
if self.condition == 0:
return "This would be better served on a pedestal in a museum"
elif self.condition == 1:
return "I mean...It works, mostly"
elif self.condition == 2:
return "This is...acceptable"
elif self.condition == 3:
return "Passable for sure"
elif self.condition == 4:
return "Lightly used, a couple scuffs, but still in good shape!"
elif self.condition == 5:
return "Like new!"

Choose a reason for hiding this comment

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

Nice job defining this in the superclass and letting the subclasses inherit it.

Comment on lines +4 to +8
if inventory == None:
self.inventory = []
else:
self.inventory = inventory

Choose a reason for hiding this comment

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

Good job avoiding a mutable default value! One small nitpick, use is None when checking whether an object is None.

Comment on lines +14 to +18
if item in self.inventory:
self.inventory.remove(item)
return item
return False

Choose a reason for hiding this comment

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

Really nice job recognizing you don't need an else here!

Comment on lines +57 to +64
their_offer = other.get_best_by_category(my_priority)
my_offer = self.get_best_by_category(their_priority)
if their_offer == None or my_offer == None:
return False
else:
self.swap_items(other, my_offer, their_offer)
return True

Choose a reason for hiding this comment

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

Great logic here!

Comment on lines +56 to +58
assert result == False
assert len(vendor.inventory) == 3
assert item not in vendor.inventory

Choose a reason for hiding this comment

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

Great asserts!

Comment on lines +37 to +38
assert len(items) == 0
assert item_b not in items

Choose a reason for hiding this comment

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

The first assert is great here, but the second one is unneeded. If the length of the items is 0, we can assume that item_b is not in items.

Comment on lines +79 to +83
assert result is True
assert len(jesse.inventory) == 3
assert len(tai.inventory) == 3
assert item_f in tai.inventory
assert item_c in jesse.inventory

Choose a reason for hiding this comment

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

Great asserts!

Comment on lines +221 to +225
assert result is False
assert len(jesse.inventory) == 3
assert len(tai.inventory) == 3
assert item_d and item_e and item_f in jesse.inventory
assert item_a and item_b and item_c in tai.inventory

Choose a reason for hiding this comment

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

These asserts have the right idea, but there's a subtle bug in them. Take a look at this snippet and see if you can figure out how this same unintuitive behavior could cause problems in your code:

data = [1, 2, 3]
a = 1
b = 99
print(b and a in data)
# Prints True

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