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?
#4
(Feb-10-2021, 03:45 PM)deanhystad Wrote: Without following the link my guess is you have a code branch inside your function that doesn't end in a return. Do you have any if statements?

No, rechecked it before. There is no if or any other conditional to prevent return at line #16. Even the line #13 prints the list 'new', i.e. one line before the return statement.
The code is stated below:
n = 4562; 
rev = 0
new= []
m = 0
 
def convert(n,m):
    print "round #:", m,"n :", n
    a = ((n+1) % 3)-1
    if n:
        new.append(a); print 'new :', new
        convert((n+1)//3,m+1)
    else:
        print 'n==',n, 'new: ::: ', new
        return new
 
print  convert(n,m), "<<---- None returned ? "
 
sum = 0
 
def value(l):
    sum = 0
    for i in range(0, len(new),1):
        sum += new[i]*(3**i)
        print "sum :" , sum
    return sum
 
print value(new),  "<<---- Value is returned "
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 jahuja73 - Feb-10-2021, 09:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read characters of line and return positions Gizzmo28 2 2,098 Nov-04-2020, 09:27 AM
Last Post: perfringo
  Return JSON records in single line using python 2.7 anandmn85 0 2,871 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