This code here:
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def evenlis(x, n = 0):
if n == len(x):
return
if x[n] % 2 == 0:
print(x[n], end = " ")
evenlis(x, n + 1)
print(evenlis(arr))
prints all even numbers from the given array, but it also returns None at the end. How can I fix this?
There is the exit()
function, which seems to remove that None, but it also ends the entire program, and I do not need that, because I have some code following this function.
Some clarification. The exit()
function was used on the 4th line, which was later replaced by return
.