Feb-11-2021, 03:48 PM
(This post was last modified: Feb-11-2021, 03:48 PM by deanhystad.)
Yes. That is the purpose of my code. To demonstrate why your convert function returns None when called with a non-zero value for n. Is the reason clear now?
Your convert function, as you wrote it, has two potential outcomes. If the value of n == 0 the function returns new. If n is any value other than 0, commit does not return a value, so the value of the function call is None. I tried to highlight this by writing convert0() to return new, and convert6(), convert2() and convert1() not returning a value. This is exactly how your code works. convert(0) returns new. convert(6), convert(2) and convert(1) do not return a value.
When your main code calls convert(4562) it does not return a value. 4562 is not 0, so the code executes the branch that executes the recursion, not the branch that returns a value. It operates just like convert(6) or convert6().
Your convert function, as you wrote it, has two potential outcomes. If the value of n == 0 the function returns new. If n is any value other than 0, commit does not return a value, so the value of the function call is None. I tried to highlight this by writing convert0() to return new, and convert6(), convert2() and convert1() not returning a value. This is exactly how your code works. convert(0) returns new. convert(6), convert(2) and convert(1) do not return a value.
When your main code calls convert(4562) it does not return a value. 4562 is not 0, so the code executes the branch that executes the recursion, not the branch that returns a value. It operates just like convert(6) or convert6().