2017-08-01 44 views
0

こんにちは私のコードで属性エラーが発生しています。初心者のプログラマであるため、どこが間違っているのか分かりません。Python3の属性エラーintオブジェクトに属性がありません

import sys 

class BankAccount(object): 

    def __init__(self, balance = 0): 
     self.balance = balance 

    def withdraw(self, other): 
     if other.balance <= self.balance and self.balance > 0: 
     self.balance = self.balance - other.balance 
     else: 
     return('Insufucient funds available') 

    def deposit(self, other): 
     if self.balance > 0: 
     self.balance = self.balance + other.balance 

    def __str__(self): 
     return('Your current balance is: {0:.2f} euro'.format(self.balance)) 

これは、任意の助けをいただければ幸いですAttributeError: 'int' object has no attribute 'balance'

言って続けています。

+0

どのように 'BankAccount'を使用していますか? – aristotll

+0

deposit():天びんに金額(引数として指定)を加えます。 withdraw():残高から金額(引数として指定)を減算します負になる) – catherine

+0

その額が 'BankAccount'インスタンスではなく' int'であるのだろうかと思います。 – aristotll

答えて

0

b1.withdraw(1)b1.withdraw(BankAccount(1))などすべて変更します。

のParam otherむしろintよりbalance属性を有するBankAccountインスタンスであるべきです。

関連する問題