Output not correcting showing in pyspark

Hi,
I am running this code in pyspark:

def sum(func,lb,ub):
… total=0
… while(lb <= ub):
… total += func(lb)
… lb += 1
return total

def id(i):
… return i

sum(id,1,10)

So output coming 1.
It should come with sum of 1 to 10.
Where is the error here.?

Thanks

Hi @HETA_GODA,
you have not give the proper indentation after while loop, and insted of defining id function you need to define func function as you pass it as parameter in sum function.
here is the correct code-

>>> def sum(func,lb,ub):
...  total = 0
...  while(lb<=ub):
...   total=total+func(lb)
...   lb=lb+1
...  return total
... 
>>> def func(i):
...  return i
... 
>>> sum(func,1,10)
55