CMU Coding Bootcamp
1def isPythagoreanTriple(a: float, b: float, c: float) -> bool:
2 """
3 Return true if all the following are True:
4 - check that numbers are ascending
5 - check that a^2 + b^2 = c^2
6 - check that a, b, and c are positive
7 """
8 return (
9 (a < b and b < c) and ((a**2 + b**2) == c**2) and not (a < 0 or b < 0 or c < 0)
10 )
11
12
13print("Testing isPythagoreanTriple()...", end="")
14assert isPythagoreanTriple(3, 4, 5) == True # 3**2 + 4**2 == 5**2
15assert isPythagoreanTriple(5, 4, 3) == False # wrong order
16assert isPythagoreanTriple(4, 5, 3) == False # wrong order
17
18assert isPythagoreanTriple(5, 12, 13) == True # 5**2 + 12**2 == 13**2
19assert isPythagoreanTriple(13, 12, 5) == False # wrong order
20assert isPythagoreanTriple(12, 13, 5) == False # wrong order
21
22assert isPythagoreanTriple(-3, 4, 5) == False # no negatives
23assert isPythagoreanTriple(0, 5, 5) == False # no 0's
24assert isPythagoreanTriple(1, 1, 1) == False # 1**2 + 1**2 != 1**2
25assert isPythagoreanTriple(3, 4, 6) == False # 3**2 + 4**2 != 6**2
26print("Passed!")