دنبال کننده ها

۱۳۹۶ مهر ۱۱, سه‌شنبه

Convert recursive function into a for loop and while loop [Python]

[ad_1]



I need to convert



def aRecursive(n):
if n is 1:
return 3
else:
return 2 * aRecursive(n-1) + 5


into a for loop and a while loop. I can't seem to wrap my mind around the process. The original function for these loops are:



a(1) = 3
a(n) = 2 * a(n-1) + 5


An answer and explanation would help out immensely.




[ad_2]

لینک منبع