I need to define a function called rec_range(n) which takes a natural number and returns a TUPLE of numbers up to the number n.
i.e. rec_range(5) returns (0,1,2,3,4)
I would write it as follows:
def rec_range(n): if n < 1: return () else: return rec_range(n - 1) + (n - 1,) print(rec_range(4)) # prints (0, 1, 2, 3)
This can also handle negative arguments.