口座への入金と出金を行うシンプルなプログラムです。私はクラスをテストするだけでクラスを学ぼうとしています。
class bank:
def __init__(self):
self.origBal = 0
def deposit(self, amount):
self.origBal += amount
def withdraw(self, amount):
self.origBal -= amount
b = bank()
d = bank()
w = bank()
私が抱えている問題は、おそらく出力から最もよくわかります。
たとえば、ここに出力があります。
w.withdraw(3423)
b.origBal
-3423
d.deposit(3423)
b.origBal
-3423
d.deposit(322423)
d.origBal
325846
d.deposit(3223)
d.origBal
329069
w.withdraw(324334)
b.origBal
-3423
w.withdraw(234)
b.origBal
-3423
何が起こっているのか正確にはわかりません。
(-n) または (+n) を手動で入力するだけで修正できると確信しており、方法は 1 つしかありませんが、それは避けたいと思います。