+ 1
Why it returned 'None'? [PS : "Was trying recursion"]
arr = [1,2,3,4,5] def rec(arr): count = 0 if min(arr) == max(arr): return count else: for i in range(len(arr)-1): arr[i]+=1 count+=1 arr.sort() If min(arr)!=max(arr): return rec(arr) arr = [1,2,3,4,5] print(rec(arr)) Why it gives 'None' as an output, I don't know if my code is correct as i just started learning recursion
3 ответов
+ 3
You have
if min(arr) != max(arr):
statement near the end of your function. But you don't return anything if they do equal each other. That's when it returns None.
Otherwise, for your first attempt using recursion, you've done well! 😉
+ 1
Thanks for the help, silly mistake tho!
+ 1
Amit Dubey Don't beat yourself up about it. We've all made them and we will all continue to make them!