The magic of aptitude in Mathematics and skill development was rendered by UNIMATH FORUM.
Can for loop be nested??
This comment has been removed by the author.
squares = []square_pair = []pythagorian_triples = []for i in range(1, 101): squares.append(i**2) for j in range(i, 101): if i != j: square_pair.append( (i**2, j**2) )for z in squares: for (x,y) in square_pair: if z == x+y: pythagorian_triples.append( ( round(x**0.5), round(y**0.5), round(z**0.5) ) )print()print("Pythagorian triples upto 100 are : ", pythagorian_triples)print()print("There are ",len(pythagorian_triples)," triples")print()
Can for loop be nested??
ReplyDeleteThis comment has been removed by the author.
Deletesquares = []
Deletesquare_pair = []
pythagorian_triples = []
for i in range(1, 101):
squares.append(i**2)
for j in range(i, 101):
if i != j:
square_pair.append( (i**2, j**2) )
for z in squares:
for (x,y) in square_pair:
if z == x+y:
pythagorian_triples.append( ( round(x**0.5), round(y**0.5), round(z**0.5) ) )
print()
print("Pythagorian triples upto 100 are : ", pythagorian_triples)
print()
print("There are ",len(pythagorian_triples)," triples")
print()