[英]I am using OOPS concept to make deposit and withdrawl using bank class. But it's showing syntax error
class Bank:
def __init__(self,owner,balance):
self.owner = owner
self.balance = balance
def __str__(self):
return f"Bank owner:{self.owner}\n Bank balance:{self.balance}"
def deposit(self,amount):
self.amount = amount
print('Deposit accepted')
return self.balance += self.amount
def withrawl (self,amount):
if self.amount>self.balance:
print('Withdrawl exceeded the available balance')
else:
return self.balance -= self.amount
print('Withdrawl accepted')
In-place operators like +=
and -=
cannot be used in a return
statement. +=
和-=
等就地运算符不能在return
语句中使用。 Modify the value first, then return it.先修改值,再返回。 Also, the last print statement is unreachable.
此外,最后一个打印语句是无法访问的。
class Bank:
def __init__(self, owner, balance):
self.owner = owner
self.balance = balance
def __str__(self):
return f"Bank owner:{self.owner}\n Bank balance:{self.balance}"
def deposit(self, amount):
print('Deposit accepted')
self.balance += amount
return self.balance
def withdrawl(self, amount):
if amount > self.balance:
print('Withdrawl exceeded the available balance')
else:
self.balance -= amount
print('Withdrawl accepted')
return self.balance
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.