Created
January 14, 2017 16:26
-
-
Save tuannvm/9ea23fa0eb0a017a4647e15fd45c3d4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Store: | |
def __init__(self, name): | |
self.name = name | |
self.items = [] | |
def add_item(self, name, price): | |
self.items.append({ | |
'name': name, | |
'price': price | |
}) | |
def stock_price(self): | |
total = 0 | |
for item in self.items: | |
total += item['price'] | |
return total | |
@classmethod | |
def franchise(cls, store): | |
cls = store | |
return "{} - franchise".format(cls.name) | |
# Return another store, with the same name as the argument's name, plus " - franchise" | |
@staticmethod | |
def store_details(store): | |
#pass | |
return "{}, total stock price: {}".format(store.name, store.stock_price()) | |
# Return a string representing the argument | |
# It should be in the format 'NAME, total stock price: TOTAL' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
In the
franchise
method, you have two arguments:cls
, a reference to the class (i.e.cls
andStore
are the same thing); andstore
, aStore
object that has a name and potentially a list of items.However, in line 20 you assign
cls = store
, which meanscls
is no longer a reference to the class.The method is meant to "Return another store", which means it must return a
Store
object. In line 21, you return a string.In order to return a
Store
object with the correct name, you should change line 21 to this:If you delete line 20, then you can use
cls
instead ofStore
(and you'll have to accessstore.name
instead ofcls.name
):