Given the following code, I've been asked to calculate how many different tuples (aliasing tuples are to be excluded) are in the returned tuple of the function:
def tuple_maker(k):
result = tuple()
length = len(result)
for i in range(k):
result = (i,result * i)
length += len(result)
print(length)
return result
res = tuple_maker(4)
This is the value of res
variable:
(3, (2, (1, (0, ()), 1, (0, ())), 2, (1, (0, ()), 1, (0, ())), 2, (1, (0, ()), 1, (0, ()))))
The given answer is 5 different tuples of which I was correct, but the second question was to calculate the total length of the tuple in res
variable. The code above prints 8
, while the answer is 14
.
What do I miss here?