[英]i am building a app using tkinter but theres an error showing “top” as an invaild syntax, how do i solve this
[英]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')
+=
和-=
等就地運算符不能在return
語句中使用。 先修改值,再返回。 此外,最后一個打印語句是無法訪問的。
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.