示例#1
0
def buystock_chain_input(context):
    '''raw input function for buystock()'''
    print "Which stock would you like to buy?"
    buy_chain = -1

    while buy_chain == -1:

        buy_chain = raw_input("Select from: " + str(infos.avail_stock(context).keys()))
        
        if buy_chain not in infos.avail_stock(context).keys():
            buy_chain = -1
        
        else: return buy_chain
示例#2
0
def buystock(context):
    '''Current player buys up to three shares of stock at the end of the turn''' 
    shares_bought = 0
    while 1 == 1:
        print "Available purchases are:"
        for h in infos.avail_stock(context).keys():
            print h + ": " + str(infos.avail_stock(context)[h]) + " shares available at $" + str(infos.price(context, h)) + " per share."
        buy_chain = inputs.buystock_chain_input(context)
        print "You have " + str(context['player'][context['cp']]['cash']) + " dollars."   
        buy_shares = inputs.buystock_amt_input(context, buy_chain, shares_bought)
        context['player'][context['cp']]['cash'] -= (buy_shares * infos.price(context, buy_chain))
        context['player'][context['cp']]['stock'][buy_chain] += buy_shares
        context['stock'][buy_chain] -= buy_shares
        shares_bought += buy_shares
        if shares_bought > 2:
                return
        else:
            done = inputs.done_input()
            if done == "N":
                return