[Tutor] Re: recursion sort of

Jennifer Cianciolo jciancio@indiana.edu
Fri May 30 16:05:02 2003


wow, this is more complicated than stuff I've seen, but I stole some
of it and wrote the following, which works only because n1 and n2
actually oscillate


def run(n1, n2):
     cycle = 1
     while 1:
         nt=n1+n2
         print nt
         if n1>=800:
             w1=0.1
             nnew1=n1*2*w1
         elif n1<=799:
             w1=1.5
             nnew1=n1*2*w1
         if n2>=800:
             w2=0.3
             nnew2=n2*2*w2
         elif n2<=799:
             w2=1.1
             nnew2=n2*2*w2
         n1=int(n1*2*w1)    #what is this 'int' thing?
         n2=int(n2*2*w2)
         cycle +=1          #and what is this? / is this why it's
recursive?


I'm glad I've got this oscillating, but I'm going to go back to basics
for a bit, both on the math and the computer stuff.

thanks a lot
Jen

-------------------
> import time
> 
> def run(n1, n2):
>     cycle = 1
> 
>     while 1:
>         nt = n1 + n2
> 
>         print 'Cycle: %4d   n1: %3d   n2: %3d   nt: %3d' % (cycle,
n1, n2, 
> nt)
> 
>         if nt > 500:
>             w1 = 1
>             w2 = 0.8
>         else:
>             w1 = 1.2
>             w2 = 1.4
> 
>         n1 = int(n1 * w1)
>         n2 = int(n2 * w2)
> 
>         cycle += 1
> 
>         time.sleep(0.2)
> 
> if __name__ == '__main__':
>     run(10, 250)
> 
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE* 
> http://join.msn.com/?page=features/junkmail
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
>