Barnsley fern in python language
Question: I need help with this Barnsley fern program. I am not getting the leaf picture
at all and getting an error run time message when I run my code I know I am
close but need some help

    
    
    #! /usr/bin/env python
    
    
    import matplotlib.pyplot as plt
    import random
    
    # starting values
    x = 0.5
    y = 0.0
    
    for i in range(10000):
            rand = (random.randrange(0,1))
            if (rand < 0.02):
                    x = 0.5
                    y = 0.27*y
            if  ((0.02 <= rand) and (rand <= 0.17)):
                    x = -0.139*x + 0.263*y + 0.57
                    y = 0.246*x + 0.224*y - 0.036
            if  ((0.17 < rand) and (rand <= 0.3)):
                    x = 0.17*x - 0.215*y + 0.408
                    y = 0.222*x + 0.176*y + 0.0893
            if ((0.3 < rand) and (rand < 1.0)):
                    x = 0.781*x + 0.034*y + 0.1075
                    y = -0.032*x +0.739*y + 0.27
    
    
    plt.plot(x,y,'.')
    plt.show()
    


Answer: There are two major issues with your code:

  1. `random.randrange(0, 1)` always yields `0`. Try using `random.random()` instead.

  2. You need to indent the `plot` command in order to have it executed in every iteration.

Furthermore, it might be better to first collect all coordinates in one large
array and then call the plot command. This would probably be more time
efficient because you'd call the rendering engine only once.

![enter image description here](http://i.stack.imgur.com/Q2E5t.png)

