In this article, we will create a python function that will produce an array with the numbers 0 to N-1 in it.

For example, the following code will result in an array containing the numbers 0 to 4:

arr(5) // => [0,1,2,3,4]

There are a few rules we need to follow here:-

  1. when the user passes in 0 to the above function, the function will return an empty list.
  2. when the user passes in an empty argument into the above function, the function will also return an empty list.
  3. any other positive number will result in an ascending order array.

Below is the full solution to the above problem.

def arr(n=None): 

    li = []
    if n == 0 or n == None:
    	return li
        for i in range(n):
        return li

Write down your own solution in the comment box below this post 🙂

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *