pythagorean triples exercise

Peter Pearson ppearson at nowhere.invalid
Fri Oct 22 19:05:10 CEST 2010


On Fri, 22 Oct 2010 01:35:11 -0400, Terry Reedy <tjreedy at udel.edu> wrote:
> On 10/21/2010 7:55 PM, Baba wrote:
>
>> the bit i'm having difficulties with in constructing my loops is:
>> "whose small sides are no larger than n"
>
> from math import sqrt
>
> def py_trips(n):
>    for b in range(4,n+1):
>      for a in range(3,b+1):
>        cf = sqrt(a*a+b*b)
>        c  = int(cf)
>        if c == cf: yield a, b, c
[snip]

Is it important to let "a" range all the way up to b, instead of
stopping at b-1? (tongue in cheek)

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list