-1
Well, it follows my code that aims to find the inverse of a list in python through recursive
def inverso(n, seq):
if len(seq) == 0:
return
else:
ultimo_valor = seq[n-1]
print(ultimo_valor, end=' ')
seq.pop()
inverso((n-1), seq)
n = int(input())
sequencia = []
for c in range(n):
if n >= 1 and n <= 100:
sequencia.append(int(input()))
print(inverso(n, sequencia))
The problem arises at the moment that is appearing a None at the end, thing that was not supposed to appear
#entrada
5 #tamanho da sequencia
1
3
6
4
3
#saída
3 4 6 3 1
The output must be on the same line and separated by a space. Thanks in advance.
Okay, thank you. In my case it’s the other way around.
– Gabriel Schrader
The answer is simpler than it looks. During its inverse function it performs prints, but returns no value. Then when you print a function that does not return any value, the 'None' will appear. Try calling the recursive function out of print to see the result.
– Octávio Lage