B
Baba
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.
Try it with n <= 200."
what is "n" ? i am guessing that it is a way to give a bound to the
triples to be returned but i can't figure out where to fit in "n".
a^a + b^b = c^c is the condition to satisfy and i need to use loops
and "n" will be an upper limit of one (or more?) of the loops but i am
a bit lost. Please help me get thinking about this right.
import math
for b in range(20):
for a in range(1, b):
c = math.sqrt( a * a + b * b)
if c % 1 == 0:
print (a, b, int(c))
this returns
(3, 4, 5) (6, 8, 10) (5, 12, 13) (9, 12, 15) (8, 15, 17) (12, 16, 20)
is that the desired output? what is the step that i'm missing?
thanks in advance
Baba
p.s. this is not homework but self-study
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.
Try it with n <= 200."
what is "n" ? i am guessing that it is a way to give a bound to the
triples to be returned but i can't figure out where to fit in "n".
a^a + b^b = c^c is the condition to satisfy and i need to use loops
and "n" will be an upper limit of one (or more?) of the loops but i am
a bit lost. Please help me get thinking about this right.
import math
for b in range(20):
for a in range(1, b):
c = math.sqrt( a * a + b * b)
if c % 1 == 0:
print (a, b, int(c))
this returns
(3, 4, 5) (6, 8, 10) (5, 12, 13) (9, 12, 15) (8, 15, 17) (12, 16, 20)
is that the desired output? what is the step that i'm missing?
thanks in advance
Baba
p.s. this is not homework but self-study