pythagorean triples exercise

Baba raoulbia at gmail.com
Thu Oct 21 19:55:26 EDT 2010


On Oct 21, 10:18 pm, Terry Reedy <tjre... at udel.edu> wrote:
> On 10/21/2010 6:55 AM, Baba wrote:
>
> > Hi everyone
>
> > i need a hint regarding the following exercise question:
>
> > "Write a program that generates all Pythagorean triples whose small
> > sides are no larger than n.
>
> This is not well worded. I take 'small sides' (plural) to mean the two
> smaller, non-hypotenuse sides (which are necessarily shorter than the
> hypotenuse). So the possible pairs of values i,j, where i is the shorter
> of the two, have
>
> > Try it with n<= 200."
>
> Again, not well worded; I believe this is meant to be n==200, except
> that the program should take n as a parameter and then give it value
> 200, so that the could work if n were given some other value.
>
> So the possible pairs of values i,j, where i is the shorter of the two,
> have j <= n (==200) and i <= j.
>
> --
> Terry Jan Reedy

Hi Terry,

the full exercise reads as follows:

Write a program that generates all Pythagorean triples whose small
sides are no larger than n. Try it with n <= 200. (Hint: Use two for
loops to enumerate
possible values for the small sides and then test to determine whether
the result
is an integral square.

source: http://users.soe.ucsc.edu/~pohl/12A/ch03-state.pdf (exercise
11, it's a Java book but i like to use Python for solving such basic
exercises as it is a much less cumbersome language)

i agree that possibly the wording makes this more difficult than it
is. Anyway, i'm a beginner so my problem solving techniques are still
quite shaky.

the bit i'm having difficulties with in constructing my loops is:
"whose small sides are no larger than n"
i don't know what to do with that :(

Baba



More information about the Python-list mailing list