Home > Net >  Why my code is not running and not showing any results?
Why my code is not running and not showing any results?

Time:06-15

#user details, parent class
class User():
    def __init__(self, name,age, gender ):
        self.name=name
        self.age=age
        self.gender=gender
    def show_details(self):
        print('personal details')
        print('Name', self.name)
        print('Age', self.age)
        print('Gender',self.gender)

#child class
class Bank():
    def __init__(self,name ,age , gender):
        super().__init__(name,age,gender)
        self.balance=0
    def deposit(self,amount):
        self.amount=amount
        self.balance=self.balance   self.amount
        print('Account balance has been updated : ' ,self.balance)

    def withdrawl(self, amount):
        self.amount=amount
        if self.amount>self.balance:
            print("Onsufficient balance")
        else:
            self.balance=self.balance-self.amount
            print("Account balance has been updated: " , self.balance)

    def view_balance(self):
        self.show_details()
        print("Account balance: ", self.balance)

CodePudding user response:

you have to create instances of classes to see them

CodePudding user response:

Because you didn't specify that the class is the children.

class Bank(User):
    [...]

And also create instances:

bank = Bank("Ben", 26, "Male")
bank.deposit(10) # Account balance has been updated: 10
bank.withdrawl(15) # Onsufficient balance
  • Related