Created
May 23, 2017 04:06
-
-
Save saegeullee/8f58dd800f343ea6c934a10d7eec32dc to your computer and use it in GitHub Desktop.
example
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 Retailer: | |
| price_of_computer = 100000 | |
| price_of_computer_from_vendor = 50000 | |
| def __init__(self, money, product, place): | |
| self.money = money | |
| self.product = product | |
| self.place = place | |
| def sell(self, other, product): | |
| total_price = product * self.price_of_computer | |
| self.money += total_price | |
| other.money -= total_price | |
| self.product -= product | |
| other.product += product | |
| print("sell {} products".format(product)) | |
| def buy_from_vendor(self, other, product): | |
| spent_price = self.price_of_computer_from_vendor * product | |
| self.product += product | |
| self.money -= spent_price | |
| def __str__(self): | |
| return "money : {}, product = {}, place = {}".format( | |
| self.money, self.product, self.place | |
| ) | |
| class Buyer(Retailer): | |
| def __init__(self, money, product, place): | |
| super().__init__(money, product, place) | |
| def buy(self, other, product): | |
| total_price = other.price_of_computer * product | |
| self.money -= total_price | |
| self.product += product | |
| def __str__(self): | |
| return "money : {}, product = {}, place = {}".format( | |
| self.money, self.product, self.place | |
| ) | |
| R = Retailer(0, 10, '신사') | |
| B = Buyer(500000, 0, '압구정') | |
| print(R) | |
| print(B) | |
| R.sell(B, 3) | |
| print(R) | |
| print(B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment