Tree growing algorithm

I am trying to write a tree growth algorithm where trees go through 2 growth cycles each year. The first growth cycle occurs during spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter.

The problem is that now a new tree is installed at the beginning of spring. Its height is 1 meter. I want to find the height of a tree after N growth cycles?

I did some research on recursive functions in which a function calls it itself. I am here, it makes the code that you write more elegant and simple, while loops. I am having trouble performing this function, although

n = input('How long would you like the tree to for?: ')


def cycle(n):
 if n == 0:
    n = + 1
    return n
    print '/n' # The reason for all the '/n' is just for neatness. 
    print('The tree will be ' + n + 'Ft tall')

 elif n % 2 == 0:
    n = 1 + cycle(n - 1)
    return n
    print '/n'
    print('The tree will be ' + n + 'Ft tall')

 elif n % 2 != 0:
    n = 2 * cycle(n - 1)
    return n
    print '/n'
    print('The tree will be ' + n + ' Ft tall')

 cycle(n)
+4
source share
1 answer

n . ! , n , , , .

, , . - , .

0

All Articles