If I run the program, t although the beginning part of the program works quite well, the last line of the program shows the balance 0 and it is different from the results that we can get from the second last line.

I am getting very confused with why it works like this. Could anyone explain why the program works like this and tell me how to fix the bug please?

Thank you in advance!

"""The program is to virtually create a bankaccount"""
class BankAccount(object):
    balance = 0
    def __init__(self, name): = name
    def __repr__(self):
        return "%s's account. Balance: $%.2f" % (, self.balance)
    def show_balance(self):
        print "%s's account. Balance: $%.2f" % (, self.balance)
    def deposit(self, amount):
        if amount <= 0:
          print "Depositing..."
        print float(amount)
        self.balance += amount
    def withdraw(self, amount):
        if int(amount) > int(self.balance):
            print "The amount you can withdraw should be less than or equal to your balance!"
            print "Withdraw amount: %s" % (amount)
            self.balance -= amount
my_account = BankAccount("Sean")
print my_account
print my_account.show_balance()
a = BankAccount("Sean")
print my_account


i am confused about this line:

a = BankAccount("Sean")

why create another class instance? You can simply deposit and withdraw from my_account?


Oh, I didn't notice that :joy:. Never mind. Could you please help solve my problem please?


if you then deposit and withdraw from my_account, it should be good? I didn't see further problems


Sorry but my point is that the outcome of the last step should be 1500. But it turned out 0. I'm confused about this.


because you deposit and withdraw from a class instance (this should be my_account instance), and then you expect change have happened to my_account instance


Oh I finally realize the problem. Thank you!