How to change the value of a local variable (python) each time the code loops?
Question: I have to create an ATM style program wherein the code looks something like
this:

    
    
    import sys
    def ATM():
        bank = 0
        coins = int (input ("Enter coins: "))
        bank = coins+bank
        o = input("would you like to take out 20p? Y or N")
        if o == "Y":
            bank = bank - 20
        else:
            print ("your balance is {0}".format(bank))
        op = input ("would you like to enter more coins? Y or N")
        if op == "Y":
            ATM()
        else:
            print ("goodbye")
            sys.exit()
        ATM()
    

Is there a way to make the local variable bank keep it's value from the end of
the program? what would I have to switch bank = 0 for? EDIT: Found a solution,
thank you all who offered some suggestions


Answer: You can use [pickle](https://docs.python.org/2/library/pickle.html) or you can
save your data in to a .txt file;

    
    
    #codes
    ....
    with open("my_database.txt","a+") as f:
        f.write(str(bank))
    

So you could keep your `bank` data in a file. As you see we open the file in
`a+` mode which is not overwriting your file.

