Given a number, return a list of integer with python function.

In this chapter, we are given a number and we need to return a list of integer based on that number, for example, number 3 will return a list of [1,2,3].

We will first create an empty array, then we will loop through that number and push the new number (count + 1) into that empty list.

def monkey_count(n):
    li = []
    for i in range(n):
        li.append(i+1)
    return li

There is one easy solution as compared to the above, let me know in the comment box below this post.

Click to rate this post!
[Total: 0 Average: 0]
Please follow and like us:
error0

2 Comments

Leave a Reply

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