(Untitled)

Nov 10, 2013 18:30


# -*- coding:utf8 -*-
class GetResult:
result=[]
def add(self,x,y):
z= x+y
self.result.append(z)

rs=GetResult()
rs.add(1,2) #the result is [3]
print rs.result
rs.add(3,4)#the result is [7] #what i want the is [4]
print rs.result

Leave a comment

Comments 3

ravendisplayed November 11 2013, 06:25:10 UTC
Not quite certain which 4 you want, since there are several combinations that could get that with the numbers you have chosen, but...

rs.result[-1] - rs.result[-2]

seems like most obvious.

WTF are you trying to do? I thought you were an anti-Dutch bigot anyway.

Reply

two_pi_r November 11 2013, 06:47:23 UTC
Who says I wrote this? :p

Reply


That's not what I got; love, Rardiff anonymous December 24 2014, 15:44:41 UTC
>>> class GetResult:
... result = []
... def add(self, x, y):
... z = x + y
... self.result.append(z)
...
>>> rs=GetResult()
>>> rs.result
[]
>>> rs.add(1,2)
>>> rs.result
[3]
>>> rs.add(3,4)
>>> rs.result
[3, 7]
>>>

Reply


Leave a comment

Up