Since you are trying to learn the code, I will not give you a complete solution, but I will give you some tips:
You have a for loop that runs from 1 to n (using range(1, n+1) ) instead of your while -loop. This will generate the values ββyou want to propagate and repeat the correct number of times (which can sometimes be a bit complicated with while loops).
Have a variable called product to store the result of the multiplications every time through the loop.
Initialize product before entering for -loop. Inside, you will simply update the value of product .
After you finish the loop, you can use the return to return the value of product .
Finally, for testing, you can start with a small n , like 4, and print the values ββthat you calculate inside the loop to check how your code works.
There are more subtle and pythonic ways to do this, but it uses the code structure that you have already configured. And, of course, recursively, and also you mention.
Once you have mastered the basics, you will appreciate more idiomatic ways of writing this document, or you will invoke the appropriate functions that will do this for you.
source share