ps3, problem 2 Hello How to solve problem 2 in ps3 recursively? 2 days are gone and there is no result. I am fascinated with recursion but I gave up. Would you please show the way?
Hint: All recursive functions follow a typical pattern. First, define the base case. The base case is where the recursion will stop. Second, specify the rule which is followed in each step other than the base case. Below I have defined a recursive function for generating factorials and fibonnaci numbers. The fibonnaci definition is slightly trickier since it requires two base cases. def factorial(n): if n==1: <----base case return n else: <----rule return n * factorial(n-1) print factorial(t) def fib(n): if n==0: <----base case return 0 elif n==1: <----base case return 1 else: return fib(n-1)+fib(n-2) <---rule print fib(t)
@malpaso I am familiar with concept and these examles. But somehow your explanation gave me energy to give one more try. Thank you. @bwCA. Thank you very much
Join our real-time social learning platform and learn together with your friends!