Skip to content Skip to sidebar Skip to footer

Python Newbie Questions - Not Printing Correct Values

I am newbie to python and I doing doing some OOPS concept exploring in Python. Following is my Account class: class Account: def __init__(self,balance): self.__balance=

Solution 1:

With the double -- (negative) you are subtracting a negative value (i.e. adding a positive value). A more clear explanation would look like:

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

Therefore, change this:

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

To this:

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

Or better yet, to this:

self.__balance -= int(withdraw_amt)

Solution 2:

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

is actually parsed as

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

which is to say, it is adding the withdraw amount. try with a single -

Post a Comment for "Python Newbie Questions - Not Printing Correct Values"