+ 1
why output is 8?
8 ответов
+ 1
when y == 0, it starts to "unwind"
The last call to the function .. 1 is returned...
(the number in brackets is the number returned from the previous call
2 * (1) = 2;
2 * (2) = 4;
2 * (4) = 8
this helped me:-
https://www.youtube.com/watch?v=kepBmgvWNDw&list=PLBlnK6fEyqRhX6r2uhhlubuF5QextdCSM&index=75
+ 7
return x*f(x,y-1)
Is called recursion. The function calls itself again but with an updated value, which leads to the exit condition.
+ 6
I'm sorry, I'm not sure I understand your question.
You have a function f(x, y)
In that function there is an else condition which returns x* f(x,y-1)
That return calls the original function again but with a new y value.
If we put the numbers in:
2* f(2, 3-1)
2* f(2, 2-1)
2* f(2, 1-1) -> now y == 0, so it will end
+ 2
Thanks to everyone, I finally figured it out
+ 1
Although the video is in about "C", the logic is the same. Pay particular attention to the last 5 min.
+ 1
print("Wow you have created pow() function.")
If you want to check:
print("Check")
else:
print("scroll up")
0
But, why( x* (x,y-1)) change to ( x* (x*(y-1))?
0
where does the action come from instead of a comma