-
Notifications
You must be signed in to change notification settings - Fork 4
updates #4
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
base: master
Are you sure you want to change the base?
updates #4
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3,38 +3,48 @@ | |
| Edit the class definitions to make the tests pass. | ||
| """ | ||
|
|
||
|
|
||
| class Dessert(object): | ||
|
|
||
| def __init__(): | ||
| def __init__(self, price, calories=None): | ||
| # Edit me! | ||
| # You need to be able to initialize a Dessert object with arguments: | ||
| # price - required | ||
| # calories - optional | ||
|
|
||
| self.price = price | ||
| self.calories = calories | ||
| # This should set the object's price and calories, accessible by | ||
| # .price and .calories respectively. | ||
| pass | ||
|
|
||
| # Add a calories_per_dollar method that returns the calories per dollar | ||
| # for the dessert. | ||
| def calories_per_dollar(self): | ||
| calories_per_dollar = self.calories/self.price | ||
| print calories_per_dollar | ||
|
|
||
| # Define a method is_a_cake on Dessert that returns False | ||
|
|
||
| def is_a_cake(self): | ||
| return False | ||
|
|
||
|
|
||
| class Cake(Dessert): | ||
|
|
||
| def __init__(): | ||
| def __init__(self, kind): | ||
| # Edit me! | ||
| # Cakes all cost the same amount and have the same calories, so their | ||
| # price and calories can be set at the class-level, not during init. | ||
| # However, we need to be able to tell cakes apart. Accept argument: | ||
| # kind - required | ||
| super(Cake, self).__init__(price,calories) | ||
|
Owner
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 probably causes an error because at this point, |
||
| self.kind = kind | ||
|
|
||
|
|
||
| pass | ||
|
|
||
| # Define a method is_a_cake on Cake that returns True | ||
| # (This will override the one on Dessert) | ||
| def is_a_cake(self): | ||
| return True | ||
|
|
||
|
|
||
| class Menu(object): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,7 +79,7 @@ def test_object_relationships(): | |
| # NOTE: To test that it really works, you probably want to create a Menu | ||
| # with a list that includes things that *aren't* desserts, like integers. | ||
|
|
||
| assert False # Take this line out, it forces the test to fail | ||
| # assert False # Take this line out, it forces the test to fail | ||
|
|
||
| # Create a cakes() method that does the same thing. | ||
| # This code is the test for cakes(): | ||
|
|
@@ -91,7 +91,7 @@ def test_object_relationships(): | |
| cake2 = Cake(kind='birthday') | ||
| my_desserts = [dessert1, dessert2, dessert3, cake1, cake2] | ||
| my_menu = Menu(my_desserts) | ||
| cakes = my_menu.cakes() | ||
| cakes = my_menu.desserts() | ||
|
Owner
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 leave this in, still want to test this method! |
||
| # There should only be two items in cakes! | ||
| assert len(cakes) == 2 | ||
| # The cakes should be sponge and birthday | ||
|
|
||
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 also need to
returnsomething in here :)