# this file available at: https://arachnoid.com/files/python01/ import math from dataclasses import dataclass # pythagorean triple: # https://mathworld.wolfram.com/PythagoreanTriple.html # https://en.wikipedia.org/wiki/Pythagorean_triple @dataclass class Triangle: a: int b: int c: int def sum_of_squares(self): return self.a**2+self.b**2 def hypotenuse(self): return (self.sum_of_squares())**0.5 def triple_test(self) -> bool: if math.gcd(self.a,math.gcd(self.b,self.c)) == 1: return self.hypotenuse() == self.c else: return False def triangle_test(): for values in ((3,4,5),(5,12,13),(7,24,25),(2,4,6)): triangle = Triangle(*values) print(f'for triangle values a,b,c = {list(values):}:') print(f'\tSum of squares: a^2 + b^2 = {triangle.sum_of_squares():.1f}') print(f'\tHypotenuse : sqrt(a^2+b^2) = {triangle.hypotenuse():.1f}') print(f'\tPythagorean triple: {triangle.triple_test()}') def main(): triangle_test() if __name__ == "__main__": main()