I am trying to write two functions that take an integer and return a tuple. I can get very close to what would like to return, but what I am returning has multiple parenthesis within it. for example, I want rec_range(5) to return (0,1,2,3,4) instead of (((((0, 1), 2), 3), 4).
Here are the two functions I am writing
def rec_range(n):
'''Takes a natural number n and returns a tuple of numbers starting
with 0 and ending before n.
Int-->Tuple'''
if n == 0:
return
if n == 1:
return 0
if n >= 1:
return rec_range(n-1),(n-1)
def squares_tuple(n,m):
'''Takes a natural numbers n and m and returns a tuple of the squares
of all the natural numbers starting with n and ending with m-1.
Int,Int-->Tuple'''
while n<=m:
return n * n, squares_tuple(n + 1, m)