Calling a function from another function within the same class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cindrajit
    New Member
    • May 2015
    • 1

    Calling a function from another function within the same class

    Code:
    class calculator():
        def __init__(self,x=0,y=0):
            self.first=x
            self.second=y
            #calculator.param=+theta
       
        def scaleparam(self,theta):
            self.theta=theta
            return self.theta
    
        def addition(self,theta):
            self.addition1=(self.first+self.second)*self.scaleparam(theta)
            return self.addition1
       
            
    
    check1=calculator(3,4)  
    
    check1.scaleparam(10)
    
    print "the addition1 is "+str(check1.addition())
    ## Got error TypeError: addition() takes exactly 2 arguments (1 given)##
    Last edited by bvdet; May 15 '15, 05:56 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You need to define identifier theta and pass theta to the function call as in:
    Code:
    theta = 1
    print "the addition1 is "+str(check1.addition(theta))

    Comment

    Working...