The purpous of using recursion instead of using for i in range(11):
is because its advantagous to start from the top trying to solve a specific mathematical problem. The function will be changed so that it only returns [n]
that matches certain criteria.
print(numbers)=[[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
Why is there extra brackets?
print(numbers[7])=IndexError: list index out of range
Has this anything to do with the extra brackets?
# A function that is supposed to help sorting numbers in a list
def sorting_numbers(n):
if n > 1:
return [n] + sorting_numbers(n-1)
else:
return [1]
numbers = []
n = 10
numbers = (sorting_numbers(n))
print(numbers)
print(numbers)=[[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]
Why is there extra brackets?
print(numbers[7])=IndexError: list index out of range
Has this anything to do with the extra brackets?