简体   繁体   中英

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM