Question: For example, let's say I'm trying to create a wallet system in python where money can be add to and taken out of. I try this code here:

```
balance = 0
def addmoney(x):
    x += balance
addmoney(10000)
print(balance)

```

but it just gave me 0.
so then I tried this:

```
def addmoney(x):
    balance = 0 
    balance += x

```

And I realized that this would set the money back to 0 every time the user adds money, which I didn't want. Is there a solution to this?

Answer: 
You could declare the *balance* variable as global inside the function.

```
balance = 0
def addmoney(x):
    global balance
    balance += x
addmoney(10000)
print(balance)

```
This is usually do with OOP:

```
class BankAccount:

    def __init__(self, owner, balance, currency):
        self.owner = owner
        self.balance = balance
        self.currency = currency

    def print_balance(self):
        print("Your current balance is:")
        print(self.balance)

    def make_deposit(self, amount):
        if amount > 0:
            self.balance += amount
        else:
            print("Please enter a valid amount.")

    def make_withdrawal(self, amount):
        if self.balance - amount >= 0:
            self.balance -= amount
        else:
            print("You don't have enough funds to make this withdrawal.")

```

To call the function:

```
my_savings_account = BankAccount("Pepita Perez", 45600, "USD")
my_savings_account.print_balance()
my_savings_account.make_deposit(5000)
my_savings_account.make_withdrawal(200)
my_savings_account.print_balance()

```