[Tutor] functions and iterations

xDog Walker thudfoo at gmail.com
Tue Nov 13 06:01:48 CET 2012


On Monday 2012 November 12 19:56, Rufino Beniga wrote:
> def IterateLogistic(x,r,n):
>     for i in xrange(n):
>         x = r*(1-x)
>         if i = n:
>             print x
>
> I want this function to take in x and r which can be any two real numbers
> and after a certain number of iterations (n), the function should print the
> current state which is x. I tried this function and it doesn't do anything.
> May you please tell me what i did wrong?
Python 2.7.2 (default, Oct 10 2011, 10:47:36)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def IterateLogistic(x,r,n):
...     for i in xrange(n):
...         x = r*(1-x)
...         if i = n:
  File "<stdin>", line 4
    if i = n:
         ^
SyntaxError: invalid syntax
>>>             print x      
-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.


More information about the Tutor mailing list