Answer to Question #218063 in Python for SSK

Question #218063
A Pythagorean triplet is a set of three integers a, b, and c such that a2+ b2 = c2. In the given limit L, find the number of Pythagorean triplets R that can be formed (such that a < b < c).

Input
The first line is an integer L.

Explanation
For L = 20, Pythagorean triples satisfying the condition a < b < c are

(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15), (8, 15, 17), (12, 16, 20).

Hence the output should be 6.
1
Expert's answer
2021-07-17T10:42:22-0400
n = int(input('Enter your number here: '))
list1 = []
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if i **2 +j**2 == k**2:
                list1.append([i,j,k])
list2 = [sorted(x) for x in list1]
set1 = [tuple(x) for x in list2]
set2 = set(set1)
set3 = [list(j) for j in set2]
len(set3)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS