Felix Rosén Felix Rosén - 1 year ago 132
Python Question

pyschool Topic 4 Q 1

The task is:

Create a function generateNumbers(num) that takes in a positive number as argument and returns a list of number from 0 to that number inclusive. Note: The function range(5) will return a list of number [0, 1, 2, 3, 4].

my code:

def generateNumber(num):
numbers = []
for x in range(num):
return numbers

What is wrong? It returns a list that looks like
with double
and for
it returns

Answer Source

You are redundantly using range

You have to instead do

def generateNumber(num):
    numbers = []
    for x in range(num+1):
    return numbers         #Note where the return is

else the best you can do is

def generateNumber(num):
         return (list(range(num+1)))

Both will give you the desired result

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download