Python Forum
Why not getting return on line #16?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why not getting return on line #16?
#11
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().
Reply


Messages In This Thread
Why not getting return on line #16? - by jahuja73 - Feb-10-2021, 03:18 PM
RE: Why not getting return on line #16? - by deanhystad - Feb-11-2021, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read characters of line and return positions Gizzmo28 2 2,067 Nov-04-2020, 09:27 AM
Last Post: perfringo
  Return JSON records in single line using python 2.7 anandmn85 0 2,824 May-14-2018, 09:16 AM
Last Post: anandmn85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020