Felix Rosén Felix Rosén - 4 months ago 21
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


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