Created
December 31, 2016 18:41
-
-
Save codegenres/fd6664540a5eb31dd1e4940f7f630bc5 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
| # STOCK TICKER GAME IMPLEMENTATION | |
| """ | |
| >>> change_amount = [5, 10, 20] | |
| >>> fluctuations_direction = ['up', 'down', 'dividend'] | |
| >>> stock_types = ['Gold', 'Silver', 'Oil', 'Industrial', 'Bonds', 'Grain'] | |
| >>> def up(account,change_amount): | |
| return account+change_amount | |
| >>> def down(account,change_amount): | |
| return account-change_amount | |
| >>> account = 0 | |
| >>> class Account(object): | |
| def __init__(self, initial_balance=0): | |
| self.balance = initial_balance | |
| def up(self, amount): | |
| self.balance += amount | |
| def down(self, amount): | |
| self.balance -= amount | |
| >>> a1 = Account() | |
| >>> a1.balance | |
| 0 | |
| >>> a1.up(5) | |
| >>> a1.balance | |
| 5 | |
| >>> amount = [5, 10, 20] | |
| >>> import random | |
| >>> print(random.choice(amount)) | |
| 10 | |
| >>> def roll(dice): | |
| return random.choice(dice) | |
| >>> roll(amount) | |
| 10 | |
| >>> roll(fluctuations_direction) | |
| 'up' | |
| >>> roll(stock_types) | |
| 'Silver' | |
| >>> a1.balance | |
| 5 | |
| >>> a1.up(roll(amount)) | |
| >>> a1.balance | |
| 25 | |
| >>> class Stocks(object): | |
| def __init__(self, initial_balance=0): | |
| self.balance = initial_balance | |
| >>> Gold = Stocks() | |
| >>> Gold.balance | |
| 0 | |
| >>> account = {'Gold': 0, 'Silver': 0, 'Oil': 0, 'Industrial': 0, 'Bonds': 0, 'Grain': 0} | |
| >>> a1 = account | |
| >>> a1['Gold']+1 | |
| 1 | |
| >>> a1['Gold'] | |
| 0 | |
| >>> a1['Gold'] = a1['Gold']+5 | |
| >>> a1['Gold'] | |
| 5 | |
| >>> a1 = account | |
| >>> a1['Gold'] | |
| 5 | |
| >>> account['Gold'] | |
| 5 | |
| >>> account = {'Gold': 0, 'Silver': 0, 'Oil': 0, 'Industrial': 0, 'Bonds': 0, 'Grain': 0} | |
| >>> class Account(object): | |
| def __init__(self): | |
| self.account = {'Gold': 0, 'Silver': 0, 'Oil': 0, 'Industrial': 0, 'Bonds': 0, 'Grain': 0} | |
| >>> a1 = Account() | |
| >>> a1.account | |
| {'Oil': 0, 'Gold': 0, 'Bonds': 0, 'Industrial': 0, 'Grain': 0, 'Silver': 0} | |
| >>> | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment