pythonlambda

Python lambda expression add previous number to the given input


I need to add the previous number to the given input number using lambda function and I tried solving using lambda function syntax lambda arguments : expression to achieve below input and expected output For example Input A=5 Output 15 // 5+4+3+2+1

Issue is that it returned float numbers lambda x: (x*(x+1))/2


Solution

  • you can use this part of code

    lambda x: int((x*(x+1))/2)