Python Newbie Questions - Don't print the correct values

I am new to python and I am developing the OOPS concept in Python.

The following is the class of my account:

class Account:
    def __init__(self,balance):
        self.__balance=int(balance)

    def deposit(self,deposit_amt):
        self.__balance=self.__balance + int(deposit_amt)

    def withdraw(self,withdraw_amt):
        withdraw_amt=int(withdraw_amt)
        self.__balance=self.__balance -- int(withdraw_amt)
        print(self.__balance)
        print("Subtracting" + str(withdraw_amt))

    def get___balance(self):
        return(self.__balance)

    def __str__(self):
        return("The Balance in the Account is " + str(self.get___balance()))

Program account_test:

import account
def main():
    balance_amt = input("Enter the balance amount \t")
    new_account=account.Account(int(balance_amt))


    deposit_amt=input("Enter the Deposit Amount \t")
    new_account.deposit(deposit_amt)
    print(new_account)

    withdraw_amt=input("Enter the Withdraw Amount \t")
    new_account.withdraw(withdraw_amt)
    print(new_account)


main()

But I get the wrong output:

Enter the balance amount    3000
Enter the Deposit Amount    400
The Balance in the Account is 3400
Enter the Withdraw Amount   300
3700
Subtracting 300
The Balance in the Account is 3700

When I do withdraw, I get the added amount instead of the deductible. What am I doing wrong here?

Since I'm new, I need some suggestion in my programming practice. Is my coding style appropriate?

+1
source share
2 answers

-- () (.. ).
:

self.__balance = self.__balance - (0 - int(withdraw_amt))

:

self.__balance=self.__balance -- int(withdraw_amt)

:

self.__balance=self.__balance - int(withdraw_amt)

:

self.__balance -= int(withdraw_amt)
+2
self.__balance=self.__balance -- int(withdraw_amt)

self.__balance=self.__balance - (- int(withdraw_amt))

. -

+1

All Articles