Calling Function in Function without Arguments

Viewed 13277

Quick question:

I want to call a main function without any arguments, and within the main function, I have several other functions that do have arguments. How would I go about doing this?

Here are the multiple functions:

 # Takes the Portfolio dictionay, unpacks the multiple tuples, and calculates
 # the total price of the shares at time of purchase

def total_purchase_price(portfolio):
    totalprice = 0
    totalpurprice = 0
    for item in portfolio:
        purdate, purprice, numshares, sym, curprice = item
        totalprice += purprice * numshares
        totalpurprice = totalprice
    return totalpurprice

# Takes the Portfolio dictionay, unpacks the multiple tuples, and calculates
# the current total value of the shares

def total_value(portfolio):
    totalprice = 0
    totalvalueprice = 0
    for item in portfolio:
        purdate, purprice, numshares, sym, curprice = item
        totalprice += curprice * numshares
        totalvalueprice = totalprice
    return totalvalueprice   

# Takes the previous two functions, and subtracts them to get the total
# gain/lost of the shares

def total_gain(total_purchase_price, total_value, portfolio):
    gainlost = total_value - total_purchase_price
    return gainlost

ex. What I have right now (note: I know this won't work, just there for what I want, as each function returns a value):

def testQ1(total_purchase_price, total_value, total_gain, portfolio):
    print("Total Cost =", total_purchase_price)
    print("Current Value =", total_value)
    print("Total gain/lost =", total_gain)
    return

ex. What I want to achieve:

def testQ2():
    total_purchase_price(portfolio)
    total_value(portfolio)
    total_gain(total_purchase_price, total_value, portfolio)
    print("Total Cost =", total_purchase_price)
    print("Current Value =", total_value)
    print("Total gain/lost =", total_gain)
    return   

How would I do this? Thanks

2 Answers
Related