Right, that code won't do anything unless you call it
So you've got a call somewhere. Now what i propose is that you set balance as a global variable...
so balance = 0 as a line BEFORE those functions are called.
so after function definitions, you may have a few calls to them:
balance = 0
deposit(50)
withdraw(10)
Now the scope of balance will be a local variable within each of the functions by default. However, you can actually refer to the global variable balance (as seen initialised to 0 above) by putting in:
global balance
as the first line in each function..
so def funname(account)
global balance
balance = balance + account
the global balance part will ensure that every reference to balance within the function is referring to the global variable for balance.
Ergo, when it alters teh value of balance within the function, it's changing the global variable. When it, or another, function is called - it'll also use the global vairable, and therefore have the value it's been assigned.
Of course, if the problem wasn't accessing the balance.... then I'm not quite sure where you're having trouble
Code:
def deposit(amount):
global bal
bal = bal + amount
print "balance is ", bal
def widthdraw(amount):
global bal
bal = bal - amount
print "balance is ", bal
def balance():
global bal
print "balance is ", bal
bal = 0
deposit(50)
withdraw(10)
deposit(40)
That'd end up printing out:
balance is 50
balance is 40
balance is 80
However, don't have pyth on my system, so can't verify it - I may be talking bollocks
(typing out p*ython results in error?)