By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,562 Members | 953 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,562 IT Pros & Developers. It's quick & easy.

GIving error self is not defined

P: 1
class abc:
def __init__(self,x,y,z):
self.x = x
self.y = y
self.z = z



def add(self):
c = self.x + self.y + self.z
print " sum is ",c
# fib(self,0,1,0)
print 'hi'


def fib(self1):
#self.x = x
print self1.x
#self.y = y
print self1.y
#self.z = z
print self1.z
i = raw_input(" find series till " )
Self1.z=self1.x+self1.y
print self1.z
while self1.z <= i:
self1.z=self1.x+self1.y
self1.x=self1.y
self1.y=self1.z
print self1.z

# else:
# print "Condition fails"


# def add(self):
# c = self.x + self.y + self.z
# print " sum is ", c
# fib()


o = abc(10,20,20)
o.add()
o1 = abc(0,1,0)
o1.fib()
Jul 28 '08 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
Expand|Select|Wrap|Line Numbers
  1. class abc:
  2.      def __init__(self,x,y,z):
  3.         self.x = x
  4.         self.y = y
  5.         self.z = z
  6.  
  7.  
  8.  
  9.      def add(self):
  10.           c = self.x + self.y + self.z
  11.           print " sum is ",c
  12.          # fib(self,0,1,0)
  13.           print 'hi'
  14.  
  15.  
  16.      def fib(self1):
  17.            #self.x = x
  18.            print self1.x
  19.            #self.y = y
  20.            print self1.y
  21.            #self.z = z
  22.            print self1.z
  23.            i = raw_input(" find series till " )
  24.            Self1.z=self1.x+self1.y
  25.            print self1.z
  26.            while self1.z <= i:
  27.              self1.z=self1.x+self1.y
  28.              self1.x=self1.y
  29.              self1.y=self1.z
  30.              print self1.z
  31.  
  32.           # else:
  33.           #     print "Condition fails"
  34.  
  35.  
  36.     # def add(self):
  37.      #         c = self.x + self.y + self.z
  38.       #        print " sum is ", c
  39.       #        fib()
  40.  
  41.  
  42. o = abc(10,20,20)
  43. o.add()
  44. o1 = abc(0,1,0)
  45. o1.fib()
Please use code tags. It is difficult to follow your code without them.

Python is case sensitive. Self1 should be self1.
Jul 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.