Files
Learn-Python-Programming-Th…/ch05/pythagorean.triple.int.py
T
adii1823 ef37ce0c4e ch05
2021-10-28 17:38:16 +05:30

14 lines
400 B
Python

# pythagorean.triple.int.py
from math import sqrt
mx = 10
triples = [(a, b, sqrt(a**2 + b**2))
for a in range(1, mx) for b in range(a, mx)]
triples = filter(lambda triple: triple[2].is_integer(), triples)
# this will make the third number in the tuples integer
triples = list(
map(lambda triple: triple[:2] + (int(triple[2]), ), triples))
print(triples) # prints: [(3, 4, 5), (6, 8, 10)]