returning values from python functions -


first off apologies if has been asked before. i'm newcomer coding, you'll see.

i've simplified i'm trying achieve below.

in essence, pass 2 variables either functions below (fun1 or fun2 initiated first). once either val1 or val2 has reached 0, return alternate value. in example below, val2 reach 0 , fun1 initiated first.

i wondering if there's way return value blah? understand below example creating ridiculous loop between 2 functions, i've no idea how accomplish i'm after, without extensive if statements , singular function.

any appreciated.

    def fun1(val1, val2):         val2 -= 1         if val2 > 0:             print "val2: ", val2             fun2(val1, val2)         else:             print "val2 ended"             return val1      def fun2(val1, val2):         val1 -= 1         if val1 > 0:             print "val1: ", val1             fun1(val1, val2)         else:             print "val1 ended"             return val2      blah = fun1(10,8)     print blah 

you close, can recursively, return value returned function called, on , forth until decrements -1, , return final number blah

def fun1(val1, val2):     val2 -= 1     if val2 > 0:         print "val2: ", val2         return fun2(val1, val2)     else:         print "val2 ended"         return val1  def fun2(val1, val2):     val1 -= 1     if val1 > 0:         print "val1: ", val1         return fun1(val1, val2)     else:         print "val1 ended"         return val2  blah = fun1(10,8) print blah 

this store result in blah


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -