title: Trying to write a recursive "random walk" function
body: <pre><code>def rwSteps(start, low, hi):
      n=0
      while low &lt;= start &lt;= hi:
          print (start-low-1)*" " + "#" + (hi-start)*" ", n
          start+=random.choice((-1,1))
          n+=1
      return "%d steps" % (n-1)
  
  
  print rwSteps(10, 5, 15)
  </code></pre>
  
  <p>The above function is the function that I need to rewrite in a recursive fashion. The function takes in a starting point integer, and a low and a high point. From the starting point, the function should either do +1 or -1 from the starting point randomly until either the high limit or the low limit is reached. Here is what I have so far.</p>
  
  <pre><code>def RandomWalkSteps(start, low, hi):
  
      count = 0
      count = count + 1 
  
      if(low &lt;= start &lt;= hi):
          count = count + 1 
          start+=random.choice((-1,1))
          newStart = start
          RandomWalkSteps(newStart, low, hi)
          return count 
  </code></pre>
  
  <p>I feel like I'm pretty close, but I'm running into trouble of where to put the "count" statement so that it increments properly at every instance of recursion. Any help would be appreciated and feel free to yell at me if I left out any crucial piece of information.</p>