Skip to content

Instantly share code, notes, and snippets.

@codegenres
Created December 31, 2016 18:41
Show Gist options
  • Select an option

  • Save codegenres/fd6664540a5eb31dd1e4940f7f630bc5 to your computer and use it in GitHub Desktop.

Select an option

Save codegenres/fd6664540a5eb31dd1e4940f7f630bc5 to your computer and use it in GitHub Desktop.
# 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