我收到类型错误? [英] I am getting a type error?
问题描述
我厌倦了建立一个可存入和取出资金的银行,但我收到类型错误
这是代码:
class 帐户():
def __init __(self,name,balance,min_balance):
self.name = name
self.balance = balance
self.min_balance = min_balance
def 存款(自我,金额):
self.balance + =金额
def with_draw(self,amount):
if self.balance - 金额> = self.min_balance:
self.balance - 金额
其他:
打印( 抱歉,您已经联系到了您,最低余额)
def 声明(个体):
print (f 你,r当前余额为{self.balance})
class 当前(账户):
def __init __(self,name,balance):
super().__ init __(self,name,balance,min_balance = - 1000 )
这里是错误:
TypeError:__ init __()得到参数'min_balance'的多个值
我尝试了什么:
i搜索了oproblem,我试图在代码中给出最小余额没有值,但是当我写的时候像x =当前(ubaid,50,10)
i在翻译中插入最小余额的值,但是它给出了错误
TypeError:__ init __()需要3个位置参数但是4个被赋予
你正在使用一个额外的参数(self
)在你的super().__ init __
的调用中。它应该只是:
class 当前(帐户):
def __init __(self,name,balance):
super().__ init __(name,balance,min_balance = - 1000 )
I tired to make a bank in which one can deposit and withdraw funds , but i am getting a type error
Here is the code:
class Account():
def __init__(self, name, balance, min_balance):
self.name = name
self.balance = balance
self.min_balance = min_balance
def Deposit(self,amount):
self.balance += amount
def with_draw(self,amount):
if self.balance - amount >= self.min_balance:
self.balance - amount
else:
print("Sorry you have reached you,r minimum balance")
def Statement(self):
print(f"You,r Current balance is {self.balance}")
class Current(Account):
def __init__(self, name, balance):
super().__init__(self, name, balance, min_balance = -1000)
HERE IS THE ERROR:
TypeError: __init__() got multiple values for argument 'min_balance'
What I have tried:
i googled the oproblem , i tried to give the minimum balance no value in the code but then when i write like x = Current("ubaid",50,10)
i insert the value of min balance in interpreter but it gives an error
TypeError: __init__() takes 3 positional arguments but 4 were given
You are using an extra parameter (self
) in your call tosuper().__init__
. It should be just:
class Current(Account): def __init__(self, name, balance): super().__init__(name, balance, min_balance = -1000)
这篇关于我收到类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!