00:01
We want to write the program that takes three numbers as input.
00:06
If the three numbers form a right angle triangle, we will print a right triangle.
00:14
And for that, to solve that problem, we know that three numbers form a right angle triangle.
00:37
If and only if, this is the symbol mathematicians used to say if and only if, it's equivalent to, the three numbers satisfy the pythagorean theorem.
01:06
That is the greatest of the three numbers, let's say z square, is the sum of the squares of the other numbers, where c is the greatest of or the maximum rates of x, y, and c, and and it is called the hypotenuse, the other side of the legs of the right angle triangle.
01:55
So this is the condition that the three numbers get to verify, and for that we get to find the greatest of the three numbers first.
02:04
And that will be the hypotenuse of the right angle triangle, and the other two are the legs of the right angle triangle.
02:15
So we get to find that maximum.
02:19
So here there is a solution written in python that i've chosen that language.
02:26
So here is a python code.
02:35
And let's see what is done here.
02:40
So we get to read the three numbers.
02:43
And we remember in python when we do this input statement, python reads a stream.
02:52
Doesn't matter if inside the string there are numbers or so or strings themselves it reads everything as a string so we got to separate that information so in this case i take the string that the user enters and split that split it's using by default the blank space as separator so so the software is going to separate using the blank space and put that into a list of arrays called numbers.
03:34
So i get to see if i can convert each part of the split into a number.
03:44
In this case, we can work or we get a word with floating point numbers because numbers don't have to be into numbers.
03:53
They can be floating point numbers.
04:00
So i try to make the conversion of the same of the first element in the array numbers that is numbers at zero here and convert that to flow number, floating point number.
04:18
And if that happens correctly then we go to the next one but if that not go correctly that is the except part is what is executed then we write an error message you're trying to read the first number and exit the program first in for the second number and third number so we have three variables now number one number two number three each of these that fails give us an error and stop the program execution and if there are more than three parts on the split, the program continues to work.
05:00
That is, we, in this case, we could have three numbers and any other information that doesn't.
05:08
We could have verified that there are only three things when we split that's not necessary to go further.
05:18
So with this tricep, i think we are doing a good job in trying to take out the numbers.
05:26
That we're put into the stream which is the data that we are entering to the program.
05:35
So then after that we are going to verify because we know that the three numbers at this point of the program, the three numbers were currently introduced by the user.
05:47
We're going to see if the numbers are acceptable, but they get to be positive and that for any of the three numbers.
06:01
So if number one is less than a record zero or number two is less than equal to zero, i think they either cannot be zero because there is no less than zero in that right triangle so that the first verification neither none of the numbers can be negative or zero.
06:21
So we put a message if that happened and stop the execution.
06:27
So just to this point we have only verified information.
06:31
That was entered the user.
06:36
And now we are going to verify, effectively indeed, that the right angle, triangle is in place or not.
06:46
And as we said before, the pythagorean theorem is the one we're going to use, so we've got to find first the maximum of the three numbers, which will be the hypervenoms.
06:57
So we construct a list here.
07:01
We are constructing a list mbs.
07:06
Mbs with the three numbers we take as input so we have the list and then we use the index function in python is a method defined for any list and that method finds the number here with basis argument and we are passing a result of the max function mathematical function that takes the maximum value of an array of numbers in this case, the array nps we construct in the previous line, the maximum of that array is calculated, and we find the index in the array nps where the maximum occur.
07:52
There can be, in general, we could have more than one time, the maximum number in the array.
08:02
It will give us the first index where the maximum occurs.
08:07
And remembering that the index start from zero so the first number is index zero the second is index one and third is in this two and then the hypotenuse is going to be the array and bs at the location given by this previous statement here that is saying just where the maximum course so we're taking the value there we could have done this directly but i need the location to verify one thing more here is if we have here if we found the number that's because we want to that's true we can find the hypotenuse in general because it doesn't matter where it is located we can take the index where that happens given by the index function and then the hypotenuse will be the array access at that location, but it doesn't depend on what location it is...