Help with subclasses and classes

cadenmrice at gmail.com cadenmrice at gmail.com
Sat Jul 2 20:58:34 EDT 2016


When i run the code I get this error :
Traceback (most recent call last):
  File "C:/Python25/chapter2", line 18, in <module>
    bank=InterestAccount(5,1000,0.5)
NameError: name 'InterestAccount' is not defined

I can't find the issue, any help?


class BankAccount:
    def __init__(self,numb,bal):
        self.numb = numb
        self.bal = bal
    def showbal(self):
        print "Your balance is", self.bal
    def withdraw(self,wa):
        self.bal-=wa
        print("Your balance is now", self.bal)
    def deposit(self,da):
        bal+=da
        print("Your balance is now", self.bal)
    class InterestAccount():
        def BankAccount__init__(self,numb,bal,intrate):
            self.intrate=intrate
        def addintrest(self):
            self.bal = self.bal * self.intrate
bank=InterestAccount(5,1000,0.5)
bank.addintrest()
bank.showbal()
              



More information about the Python-list mailing list