Computer Science, asked by ProSaurav, 1 year ago

Can someone explain me how this works -

def tri_recursion(k):
if(k>0):
result = k+tri_recursion(k-1)
print(result)
else:
result = 0
return result

print("\n\nRecursion Example Results")
tri_recursion(6)

Answers

Answered by n123avya
1
Umm can you give me more details is this Visual Basic I can tell you if it is
Answered by hardiktiwari2910
0

Explanation:

in line 1 you are defining function tri_recursion which has an argument k then in line 2 there's an if condition which will execute only when the arguement k will be greater then 0 inside if condition You've declared a variable result which is storing the value of argument k added to the value of argument k-1 and then you are printing the value of result then in else condition variable result is set to be 0 and you are returning variable result as output after this function you are calling the function with 6 as the value of argument k

Similar questions