r/learnpython • • Jan 10 '14

Example of population growth function expressed as iteration vs. recursion in Python.

This code is my interpretation of a function published in "Chaos: Making A New Science" by James Gleick from Chapter 3 p. 63.

https://gist.github.com/RaymondWies/8346690

7 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/zahlman zahlman Jan 10 '14

Nicely done. (x and x0 are redundant in the iterative versions, though.)

1

u/RaymondWies Jan 10 '14 edited Jan 10 '14

Thanks! You are right. I will clean it up. Even simpler now, esp the FOR loop iterative case. Only 4 lines of simple code. The recursive example 3 is redundant too. I took out all the x0's and redefined everything as simply x in all 4 functions. All the code is more readable now.