w3resource

Python Challenges: Find the product xyz

Python Challenges - 1: Exercise-40 with Solution

Write a Python program to find the product xyz.

A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. Such a triple is commonly written (a, b, c), and a well-known example is (3, 4, 5). There exists exactly one Pythagorean triplet for which x + y + z = 1000.

Sample Solution:

Python Code:

for a in range(1, 1000):
     for b in range(a, 1000):
         c = 1000 - a - b
         if c > 0:
             if c*c == a*a + b*b:
                 print (a*b*c)
                 break

Sample Output:

31875000

Flowchart:

Python Flowchart: Find the product xyz.

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a python program to find the 1000th prime number.
Next: Write a Python program to find the first triangle number to have over n(given) divisors.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/challenges/1/python-challenges-1-exercise-40.php