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'
任何幫助將不勝感激。
你如何使用'BankAccount'? – aristotll
deposit():將金額(作爲參數提供)添加到餘額 withdraw():從餘額中減去金額(作爲參數提供)(或者說,如果提取該金額會導致餘額「可用資金不足」成爲負數) – catherine
我想知道如果這是一個'int'而不是'BankAccount'實例。 – aristotll