hi all
I haven't used python in almost 4 years, and even back then I've only learned the very basic stuff (so basically forget it all..)
Could someone give me some hints on how my codes aren't working?
right now I'm just writing random functions to practise
I think it's the xySum, xyProduct..etc functions that I messed up?
Thanks in advance!
I've tried to include x,y in the arguments for those xySum,xyProduct functions too, but still didn't work :(
I haven't used python in almost 4 years, and even back then I've only learned the very basic stuff (so basically forget it all..)
Could someone give me some hints on how my codes aren't working?
right now I'm just writing random functions to practise
class test: def __init__(self,x,y): '''Show doc''' self.x = x; self.y = y; def xySum(): '''Sum''' return x+y def xyProduct(): '''Product''' return x*y def xyDivision(): return x/y def append_a(self,a): print 'when a arrives in append_a(), it looks', a a = a + ' and like that' print 'then it looks', a return a def create_a(self): a = 'like this' print 'a in create_a() looks', a a = append_a(a) print 'after coming back to create_a(), a looks', a product = xyProduct() print product p = test(12,3) p.create_a()and here's the error
Error:Traceback (most recent call last):
File "C:/Users/William/Documents/Python Scripts/test.py", line 36, in <module>
p.create_a()
File "C:/Users/William/Documents/Python Scripts/test.py", line 30, in create_a
a = append_a(a)
NameError: global name 'append_a' is not defined
I think I'm still a bit confused about when to include self as an argument for a function, and how the return statement works..I think it's the xySum, xyProduct..etc functions that I messed up?
Thanks in advance!
I've tried to include x,y in the arguments for those xySum,xyProduct functions too, but still didn't work :(