Awesome Pythagorean Triads for beginners, using the program Python 2.5!
This document is a Copyright© 2009 by Larriken21. Terms and Conditions apply.
Pythagorean Triads
For no apparent reason, to save your friend you need to write a program that is capable of generating Pythagorean triads. To practice, you should first solve other Pythagorean-type problems.
Task 1 – find the hypotenuse
Write a python program which will ask the user for two short sides of a right-angled triangle. Based upon these numbers it will calculate the length of the hypotenuse. Example:
Enter one of the short sides?
3
Enter the other short side?
5
The third (hypotenuse) side must be 5.8309518948453007.
Task 2 – find a shorter side
Write a python program which will ask the user for two sides of a right-angled triangle, one of which is the hypotenuse. Calculate the length of the missing short side. The program will need to check whether the first or the second number entered is the longer side. Example:
Enter one of the sides (maybe the hypotenuse)?
3
Enter another side (maybe the hypotenuse)?
5
The third (short) side must be 4.0.
Task 3 – find any side
Write a python program which will ask the user for two sides of a right-angled triangle. They could enter the hypotenuse, or not – you have no way of knowing. You need to work out the possible lengths of the other side. There will usually be two answers. Example:
> Enter one of the sides?
3
> Enter another side?
5
> The third side is either 5.8309518948453007 or 4.0.
3.1) Why are there usually two answers?
3.2) When is there only one answer? Why?
Task 4 – triad test
Write a python program which takes in three numbers and says whether they are a Pythagorean triad, or whether they form a non-right angled triangle, or a non-triangle. You should not assume that the sides are listed in ascending (or descending) length order.
Examples:
|
> Enter item #1? 3 > Enter item #2? 5 > Enter item #3? 4 > You entered a Pythagorean triple (a right triangle.) |
> Enter item #1? 10 > Enter item #2? 5 > Enter item #3? 4 > You entered a non-triangle. |
> Enter item #1? 6 > Enter item #2? 5 > Enter item #3? 4 You entered a non-right triangle. |
Task 5 – generate triads
Euclid’s formula is one way to generate triads. To use it, first select any two positive integers m and n, with m > n. Then, a, b and c are defined by the equations:
Write a python program which asks the user for values of m and n generates the corresponding triad. Example:
Enter m (must be a positive integer)?
10
Enter n (must be a positive integer less than n)?
5
a = 100, b = 75, c = 125
Note that the example given generates the triad 75, 100, 125 which is a multiple of 3, 4, and 5.
5.1) what values of m and n will generate the triad 6, 8, 10?
5.2) which other multiples of 3, 4, and 5 can you generate using Euclid’s formula?
5.3) what values of m and n create these?
5.4) Can you find an example of a triad which cannot be discovered using Euclid’s formula?
5.5) Can you generate any families of triads other than the family of 3, 4, 5?
To do those above questions, it would help to methodically set out a table of all the triads you can generate with small values of m and n.
Task 6 – further triads
Write a program which is able to generate triads in other ways. The Internet has many different formula to calculate other types of triads.
A minimal solution is to simply implement another way to generate triads similar to the method used in Task 5.
However, you may wish to be creative!
Related Topics: More programming information; click here for Programming.
Mathematics: Here for What is the Pythagorean Theorem and here for The Three Triangles.
Good luck to you all, I hope you will endeavor to continue with this in the future,
Regards,
Larriken21












Leave Your Response