2

This code is giving me a headache.

time = epoch_years ## this value is 50.13452189.....

def timex(t):  ## isolaing and return decimal value of t
    print("t;",t)
    if t < 1:
        return t  
    else:
        timex(t-1)

result = timex(time)

I can't seem to get the value t returned after isolating the fractional value. There's probably an easier way to achieve what i want, though I'm hellbent on understanding why this code isn't working. --Result-- keeps coming back as --None--

1 Answers1

0

As @rdas said in his comment:

Change:

def timex(t):  ## isolaing and return decimal value of t
    print("t;",t)
    if t < 1:
        return t  
    else:
        timex(t-1)

to:

def timex(t):  ## isolaing and return decimal value of t
    print("t;",t)
    if t < 1:
        return t  
    else:
        return timex(t-1)

The return before timex(t-1) is the only change. I believe it works because the return will terminate the loop.

Dan
  • 1,238
  • 2
  • 17
  • 32