[Tutor] Help with Recurring Function

bob gailer bgailer at gmail.com
Sat Apr 26 03:35:28 CEST 2008


Sanhita Mallick wrote:
> Hi.
>
> I am struggling with a simple recurring function, but
> can't understand why this is happening. Please help.
>
> Here is the script. T(i) are trees (as in graphs).
> The program operates great, until the step where
> norm_ted is calculated. Mysteriously norm_ted becomes
> 0, even though "mag" value is calculated correctly.
> Also, strangely, sum_norm_ted also becomes zero. 
>
> What am I missing?
>   

Well for one thing, some code. What are F1, F2 and F3? What is alg?

Also your code got mangled by something in the email process leaving a 
lot of folded lines.

Your code would be a lot easier to red if you use % formatting (e.g.):

          print 'TED %s %s is %s' % str(i, j, ted)
or just   print 'TED', i, j, 'is', ted

I took the liberty of applying this to your code and reducing the indent 
size in hopes of it coming across easier to read.

Also note the the 3 statements following the for i loop do nothing 
useful, so I removed them.\

And what is the use of mean_ted? It is created but never referenced.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> T = [F1, F2, F3]
> k = len(T)
> mean_ted = {}
> for i in range(k):    
>   for j in range(k):
>     if (i != j):
>       ted = alg.ted(T[i], T[j])
>       print 'TED %s %s is %s' % (i, j, ted)
>       mag = 2 * (T[i].n + T[j].n) - 1
>       print 'MAG %s %s is %s and %s' % (i, j, mag, 2 * ted)
>       norm_ted = (2 * ted) / mag 
>       print 'norm_ted %s %s is %s and %s' % (i, j, norm_ted)
>       sum_norm_ted = sum_norm_ted + norm_ted
>       print 'sum_norm_ted %s %s is %s' % (i, j, sum_norm_ted)
>
>   


-- 
Bob Gailer
919-636-4239 Chapel Hill, NC



More information about the Tutor mailing list