Function not calling properly
<pre><code>def main():

    def load():
        name=0
        count=0
        totalpr=0
        name=input("Enter stock name OR -999 to Quit: ")
        while name != '-999':
            count=count+1
            shares=int(input("Enter number of shares: "))
            pp=float(input("Enter purchase price: "))
            sp=float(input("Enter selling price: "))
            commission=float(input("Enter commission: "))
            name = input("Enter stock name OR -999 to Quit: ")

    def calc():
        amount_paid=shares*pp
        commission_paid_purchase=amount_paid*commission
        amount_sold=shares*sp
        commission_paid_sale=amount_sold*commission
        profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
        totalpr=totalpr+profit_loss

    def print():
        print("\nStock Name:", name)
        print("Amount paid for the stock:       $",      format(amount_paid, '10,.2f'))
        print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
        print("Amount the stock sold for:       $", format(amount_sold, '10,.2f'))
        print("Commission paid on the sale:     $", format(commission_paid_sale, '10,.2f'))
        print("Profit (or loss if negative):    $", format(profit_loss, '10,.2f'))
        print("Total Profit is $", format(totalpr, '10,.2f'))
        return main()




load() #to input the values
calc()
print()
</code></pre>

<p>I'm not sure what I'm doing wrong: </p>

<p>Should I be putting in variable names into <code>def load():</code>, <code>def calc():</code> and <code>def print():</code>? </p>

<p>As I run it now, it says <code>"load"</code> is not defined. How would I go about defining <code>load</code>? And for that matter, if I didn't define <code>def calc():</code> and <code>def print():</code> how do I define those? </p>

<p>I do properly call them at the end of the code, in the order that I'd like to call them -- <code>load</code>, <code>calc</code>, and then <code>print</code>. </p>

<p>Is my "<code>return main()</code>" the right thing to do? I don't know, I Just want this code to run properly without error that's all. I'm under the impression that I'm just missing a few things. Any help would be appreciated. </p>

<p>This is a minimal working example to illustrate how one can solve what you are trying to do.</p>

<pre><code># helper for interpreting input
import ast
#: initial starting values
thing, count, cost, total = 'Nothing', 0, 0, 0

# define all functions at module indentation
def get_user_input():
    global thing, count, cost  # write to the GLOBAL names thing, count and cost
    thing = input('What have you?')  # ask for a string
    count = ast.literal_eval(input('How much do you have?'))  # ask for a string and interpret it: "3.2" =&gt; float
    cost = ast.literal_eval(input('How much does each cost?'))

def compute():
    global total  # write to global name total
    total = count * cost  # can read from global names

def pretty_print():  # not named print! we still need print to print!
    print("You have", count, thing)
    print("At", cost, "each, that makes", total, "in total")

# call functions at module indentation
get_user_input()  # ducks, 3, 42
compute()
pretty_print()
# You have 3 ducks
# At 42 each, that makes 126 in total
</code></pre>

<p>One thing to warn you about: working with global variables is generally a bad idea. For a small script it's fine, but you've already messed up the basics - globals are tricky, so avoid them whenever possible. If you just want to run these commands, do not write them as functions, execute them directly. Basically, leave away the <code>def ...</code> and <code>global ...</code> lines and put everything on the same indentation, then remove the last three lines.</p>

<p>If you really want to store and print multiple things, you need to use containers. Just assigning to a value in a loop, e.g. <code>thing = input('What have you?')</code>, will leave it at the last value entered. Instead, you need a container like a <code>list</code>. You can then <code>append</code> additional values to it.</p>

<pre><code>container = []  # [] is a list literal
for _ in range(3):  # non-infinite loop
    next_thing = ast.literal_eval(input('Place your order...\n'))
    container.append(next_thing)
print("You ordered", container)
</code></pre>

python function python-3.x calling-convention