Why is the Python launch error on the second method of this class?

advertisements

Why is is python throwing error at the second method in of this class?

class Lutany:
    formulaa = 0
    formulab = 0
    def __init__(self,num):
        self.num = num
        self.formulaa = self.formulaA()
        self.formulab = self.formulaB

    def formulaA(self):
        q = 0
        num = self.num
        while num > 0 :
            q += num + (num - 1)
            num = num - 1
        return q
        self.formulab = formulaB()

    def formulaB(self):
        num = self.num
        q = 0
        while num > 0 :
            q = q + (num * num)
            num = num - 1
        return (0.5 * q)

if(__name__ == '__main__'):

    l = Lutany(675)

    p = l.formulaa
    q = l.formulab 

    print " FormunlA returned " , str(p) , "  for 675 "
    print " FormulaB returned " , str(q) , "  for 675 "

When running I have the following error:

~$ python lutany.py
Traceback (most recent call last):
File "lutany.py", line 30, in <module>
l = Lutany(675)
File "lutany.py", line 7, in init
self.formulab = self.formulaB
AttributeError: Lutany instance has no attribute 'formulaB'


You're missing parentheses here: self.formulab = self.formulaB. Should be self.formulab = self.formulaB().