title: How do I define my own range function in Python
body: <p>Below I've attached a homework problem. So far my only code is.</p>
  
  <pre><code>def myRange(start, stop=None, step=None):
  
      if stop == None:
          stop = start
  
      if step == None:
          step = 1
  
      while True:
          if step &gt; 0 and start &gt;= stop:
              break
          elif step &lt; 0 and start &lt;= stop:
              break
          yield ('%g' % start)
          start = start + step
          break
  
      lyst = myRange(start, stop=None, step=None)
      for num in lyst:
          print(num)
  
  myRange(0, 10, 2)
  </code></pre>
  
  <p>I'm trying to get rid of the yeild and the '%g' statement and replace it with a return statement if anyone has any idea about how to do that. As well as that I am trying to make it so this truly works like a function and you can pass variables into it and get the range as a list, but I'm not sure how to do that either. Any help would be appreciated. I am very lost on this one. </p>
  
  <blockquote>
    <p>Define and test a function myRange. This function should behave like
    Python’s standard range function, with the required and optional
    arguments, but it should return a list. Do not use the range function
    in your implementation! (Hints: Study Python’s help on range to
    determine the names, positions, and what to do with your function’s
    parameters. Use a default value of None for the two optional
    parameters. If these parameters both equal None, then the function has
    been called with just the stop value. If just the third parameter
    equals None, then the function has been called with a start value as
    well. Thus, the first part of the function’s code establishes what the
    values of the parameters are or should be. The rest of the code uses
    those values to build a list by counting up or down.)</p>
  </blockquote>