00:00:04
♫ ♫ Opening Music
00:00:25
Hello! Welcome to another lesson of their course algorithm,
00:00:28
my name is Gustavo Guanabara, I am your teacher,
00:00:30
and now we're going to continue the study of operators seeing the two operators missing:
00:00:35
relational operators and logical operators.
00:00:38
Let's go to class for us to understand the difference between them and what each will do.
00:00:43
So, the last lesson we saw the entry of commands and arithmetic operators.
00:00:48
Now, we'll start seeing the Relational Operators.
00:00:52
And as the name suggests,
00:00:54
relational operators will create a relationship between variables or expressions.
00:01:00
Then you will be able to compare the variables and expressions and generate logical results,
00:01:05
as true or false.
00:01:06
Then the relational operators will generate as a result, always, a logical value.
00:01:11
Logical operators that exist in all programming languages, including,
00:01:16
ambiento in the visualg are:
00:01:23
So, it is noteworthy that there is no way to do the greater than or equal, with the same symbol under the larger,
00:01:30
as we do in mathematics, by keyboard typing issues.
00:01:34
So we will put the biggest sign followed the same space without any sign between them.
00:01:39
The same will occur pro or less,
00:01:42
and we have the last two relational operators are: equal to and different from
00:01:48
And worth noting that there as well as or greater and less than or equal,
00:01:52
It is difficult to type "different"
00:01:54
which is an equal sign "cut" in the middle.
00:01:56
So pro difference operator, I'll use a smaller signal and a higher signal,
00:02:00
typed with no space between them.
00:02:03
and then, we will go, then by a party that practice is to compare numeric values using the VisuAlg
00:02:10
and once again, as always, I will recommend.
00:02:13
Open visuAlg and Assita this class with the application open
00:02:17
no use getting you watch me do something
00:02:21
And you find that you learned
00:02:23
then the best way to learn is to practice
00:02:25
because when we practice, we make mistakes and when we make mistakes, we try to fix
00:02:30
and it is trying to fix what you learn, you never forget it
00:02:33
then I created an algorithm and I will create three variables here
00:02:38
variable A variable B variable and C, all three integer
00:02:41
declaration of variables we have seen in previous lessons
00:02:46
what I will do here is to make a simple assignment
00:02:49
"A" gets 2 "B" receives 3 and "C" receives 5
00:02:54
and now we will make some logical comparisons
00:02:57
I post here. type "A" greater than "B"
00:03:01
Then he will show me the result of If "A" is greater than "B"
00:03:06
Running the program we have "false"
00:03:09
this means . I sent write the logical result of "A" is greater than "B"
00:03:14
and here, I can see the values of the variables "A" is worth 2 and "B" is worth 3
00:03:19
"A" is not greater than "B", "A" is actually smaller than "B"
00:03:24
as a result of the "A" greater than "B". I have the logical value "false"
00:03:30
Get the idea?
00:03:30
We will here little we see the logical operators.
00:03:33
But the relational operators will always lead me a logical value
00:03:38
That is, will always return me either true or false
00:03:41
Let's see some more example
00:03:43
So I'll put here for example "A" Like "B"
00:03:46
"A" is 2 and "B" is 3 then "A" is not equal to "B".
00:03:49
So I will return "false" value.
00:03:52
This is "A" is not equal to "B"
00:03:54
Similarly I can test if "A" is different from "B"
00:03:58
"A" is 2 and "B" being 3 course "A" is different from "B"
00:04:02
Running it returns me the value "TRUE"
00:04:05
This is the answer to: "A" is different from "B"? Yes "A is different from" B "
00:04:11
And as I said earlier
00:04:13
relational operators will test the relationship enters variables, values or expressions
00:04:18
So I can make some comparisons using values
00:04:22
For example here.
00:04:24
"A" is greater than 2? He will return me "FALSE"
00:04:28
Because "A" is not greater than 2, if you check here.
00:04:31
"A" is equal to 2
00:04:33
But if I do the logical test: "A" is greater than or equal to 2?
00:04:38
Running, he has returned me "TRUE"
00:04:40
Because "A" is not greater than 2, but it is the same
00:04:44
Then one of the two operators is going to have to lead to true
00:04:48
Thus, in this manner. "A" greater than or equal to 2 results in the logical value "TRUE"
00:04:54
We do now, some logical expressions tests
00:04:59
Nothing prevents you do it here
00:05:01
I'll test if "C" is equal to "A" + "B" (A plus B)
00:05:04
We've seen the last class the arithmetic operators, and we know that this operator will perform addition
00:05:11
Then it will test if "C" is equal to "A" + "B"
00:05:14
"C" is 3, "A is 2, and" B "is 3.
00:05:17
2 plus 3 equals 5, it will lead me to the value "TRUE"
00:05:21
Let's run and see what the end result, it really was true
00:05:27
Let's do another example here, let's see if "C" is greater than or equal to "B ^ A" (B raised to A)
00:05:36
That is, it will make a test seeing if "C" is greater or equal than the result of "B ^ A" (B raised to A)
00:05:43
"B" is 3, the high 'A'.
"3" squared, 9.
00:05:48
"C" is equal to 5.
"C" is not greater than or equal to 9.
00:05:53
So. We will run and it will return me "False."
00:05:57
Because "B" high "A"
00:05:59
Of Nine (9)
00:05:59
"C" is not greater than or equal to "B" high "A"
00:06:02
But if I put here
00:06:05
If "C" is " 00:11:04,000
and in the latter case, if neither of the two are happy, for sure I will not be happy!
00:11:04
You get the idea?
00:11:05
With the operator "and" I want one thing and another.
00:11:09
No use come with only one for me, because I want both.
00:11:12
We will follow this same line of reasoning to the "OR" operator.
00:11:16
And there is even easier for you to understand, is not it?
00:11:19
Come on. We will follow the same line of reasoning.
00:11:21
"Paula" and "Keziah," and now I want Paula to be happy OR Keziah be happy.
00:11:27
If the two are happy, of course I'm happy.
00:11:31
If only Paula is happy and Keziah not, I end up being satisfied,
00:11:37
because I want Paula OR Keziah be happy.
00:11:41
Any one or the other.
00:11:43
Similarly, if Paula is not happy and is Keziah,
00:11:48
yet still happy.
00:11:50
The only case that is different in the case of the OR,
00:11:53
It is when Paula is not happy and Keziah also is not happy,
00:11:57
In this case, as I want Paula OR Keziah be happy, and neither is,
00:12:02
I do not get happy.
00:12:04
Now given to understand the difference between the operators AND and OR right?
00:12:08
In the case of And I'm only happy when Paula and Keziah stay happy.
00:12:12
Otherwise I'm not satisfied.
00:12:15
In the case of the OR, I'm happy in either case, except in the case where the two are unhappy.
00:12:22
The NOT operator is simply a logical reversal
00:12:25
If Paula is HAPPY
00:12:26
The NOT HAPPY SAD is
00:12:28
Thinking in the same way
00:12:29
If it is SAD, the SAD is NOT happy
00:12:32
So, for you generate the truth table
00:12:35
What are these tables we're doing
00:12:36
E and OR, is easy
00:12:38
All happyfaces
00:12:40
You will turn into true
00:12:42
All the sad faces, you will turn into false
00:12:44
So it's easy, is not it?
00:12:46
So whenever you have difficulty understanding the truth table
00:12:51
E and OR
00:12:52
Just draw smiley faces
00:12:54
And then replace
00:12:56
All HAPPY by V
00:12:57
And all the SAD by F
00:13:00
And so
00:13:01
You can have the two tables TRUTHS
00:13:04
The logical operators: AND and OR
00:13:06
Let's do some logical tests
00:13:08
Using that our same example
00:13:10
We were creating in Visualg
00:13:12
So we do here
00:13:14
This "Type"
00:13:15
I have to give two logical tests
00:13:16
So if I put here
00:13:18
"(True and false)"
00:13:22
He will return me
00:13:23
The value FALSE
00:13:25
Why a REAL thing and one thing FALSE
00:13:28
Give in FALSE
00:13:29
But I can also use
00:13:31
logical results generated by relational operators and test
00:13:35
We will test for example, if A is equal to B (A = B)
00:13:39
or C is greater than a (C> A)
00:13:43
Let's see the result.
00:13:45
In this case A is equal to B? 2 equals 3?
00:13:48
No! So this one will return me false.
00:13:52
C is greater than A? 5 is greater than 2?
00:13:55
This one would return me true
00:13:58
True or false, comes in that case.
00:14:01
Paola is not happy, but quesia is happy
00:14:04
as I have a "OR" my logical result will be:
00:14:07
a happy or true face!
00:14:10
So here we have the logical result of all ((A = B) or (C> A)) is true!
00:14:14
If by chance we put a parenthesis here, and we put a non front: (not ((A = B) or (C> A)))
00:14:19
it will reverse the logical result
00:14:21
So; if this here: (A = B) or (C> A) is true, not this here: (A = B) or (C> A)
00:14:25
will return me the False value!
00:14:28
So what he did was the following: A is equal to B? , no! C is higher qua A ?, yes!
00:14:34
False or true is: true and not true is: false.
00:14:39
And again, you will be able to do your logical and relational tests,
00:14:43
using: numbers, variables or expressions.
00:14:47
Remembering that to use logical operators, you can only test logical values.
00:14:53
And remember, too, that all expressions using relational operators generate logical results.
00:14:59
What I recommend is that you make several logical tests
00:15:02
like the one I just used.
00:15:04
then do tests and try to find out what is the logical result at the end.
00:15:09
if you prefer to pause the video at that point back to your visual g and do some testing,
00:15:14
and do not forget to put all your relational comparisons between parenthesis
00:15:19
because they are going to generate the logical results at the end
00:15:22
and speaking in parenthesis we have to be concerned enough with the order of precedence
00:15:26
we saw in the previous lesson that there is an order of precedence between the arithmetic operators
00:15:31
now that we have seen the two other operators, relational and logical
00:15:35
we will see a general table of how the order of precedence in expressions containing
00:15:40
arithmetic, logical and relational operations
00:15:44
therefore, we understand how to work the general order of precedence
00:15:48
an expression that has arithmetic, relational and logical operators at the same time
00:15:54
First, the arithmetic will be made
00:15:57
giving in order of precedence, we have seen previously
00:16:00
the parentheses, then exponentiation, soon after, multiplication and division, and finally, the additions and subtractions
00:16:09
after all arithmetic expressions are resolved
00:16:13
They will be held all relational operations
00:16:16
within the relational operators, which are "higher," "lower," "greater than or equal", "less than or equal", "equal" and different
00:16:22
Everyone has the same order of precedence, and will always run from left to right
00:16:27
Finally, after being solved the arithmetic expressions and relational
00:16:32
execute all logical operations
00:16:34
starting with 'E', soon after the 'OR' and finally the 'NO'
00:16:39
save this table in your mind, this is the execution order of all the operators that can be used within an algorithm
00:16:47
Now it's easy right ?!
00:16:49
Now we have gathered all the information about operators, you can now go for something bigger
00:16:56
which is a more complex exercise using relational and logical arithmetic operators
00:17:02
along with the input commands and output that we have seen previously
00:17:06
let's think then in an exercise that uses all that we've seen so far, including the variables
00:17:12
let's make an example that later will be more complete
00:17:15
but for now since the work for us
00:17:18
I'm going to do is this, surely you know triangles
00:17:22
what I will do here is to read three sides of a triangle, which I'll call L1, L2 and L3
00:17:30
These values will be real ( 'L1, L2, L3: Real'). And I'll make a logical test to see if this triangle can be equilateral or scalene.
00:17:39
WHAT will lead me into a logical test ( 'logical')
00:17:43
if you remember the triangles study equilateral triangle is one that has three equal sides
00:17:48
the scalene triangle is one that has three different sides
00:17:52
for now I will not worry if the three values that were actually typed form a triangle
00:17:58
because there is a mathematical rule for this. But with us 'ok' at first, we will not see this mathematical rule yet.
00:18:04
We will see later on in a more complex exercise.
00:18:07
in fact, we read three values and see if they are totally equal to each other,
00:18:13
or completely different.
00:18:15
we do the testing here and understand how the relational and logical operators work
00:18:20
so here, vamomos start asking the user to enter the three sides
00:18:25
Write ( "enter the first side")
00:18:31
Read (L1)
00:18:33
I will do the same for the other two sides
00:18:37
the procedure is exactly the same
00:18:40
only the read will play the value in another variable
00:18:44
Finally, I will do so with the third. Read (L3)
00:18:50
now I've done three of reading
00:18:53
what I will do is to check if the triangle is equilateral
00:18:57
EQ will receive the logical outcome of the tests of the three sides ( 'EQ 00:20:38,280
it is checking whether the triangle will be equilateral
00:20:38
or scalene
00:20:39
we will do some tests
00:20:40
running
00:20:42
First side 3
00:20:43
second side
00:20:44
two
00:20:45
third side
00:20:46
4
00:20:47
three two four
00:20:49
are three different values each other
00:20:51
soon
00:20:52
would form
00:20:52
a scalene triangle
00:20:54
let's check
00:20:55
the equilateral triangle can not be
00:20:57
but it can be scalene
00:20:59
let's go back.
00:21:00
rerun
00:21:01
and we put 4, 4:04
00:21:05
which form an equilateral triangle
00:21:08
The triangle is equilateral? true.
00:21:11
The triangle is scalene? false.
00:21:13
Let's do another test
00:21:15
it will be four (4) four (4) and three (3)
00:21:21
Here, we have two equal sides and a different
00:21:24
What would lead me an isosceles triangle.
00:21:27
We are not testing in this case
00:21:29
But it will be neither equilateral nor scalene ..
00:21:32
The logical result:
00:21:34
The triangle is equilateral? False
The triangle is scalene? False
00:21:38
And just remember what I said
00:21:40
There is a mathematical rule
00:21:41
To verify that the three sides can form a triangle
00:21:45
And this logical test is simple
00:21:47
Each side must be less than the sum of the other two sides
00:21:52
So if I have side L1, L2 and L3
00:21:55
L1 must be less than the sum of the other two
00:21:58
L2 must be smaller than the sum of the other two
00:22:00
And L3 must also be less than the sum of the other two.
00:22:04
And note that I used the logical operator "and" in my sentence
00:22:07
So let's create another logical variable to see if it can be a triangle.
00:22:13
Then I'll create a new logical value called "TRI".
00:22:17
That will determine whether it can be a triangle
00:22:20
My variable "TRI" will receive the logical result
00:22:23
L1, is less than the sum of L2 to L3
00:22:29
Note here that this expression
00:22:31
the arithmetic operators have higher precedence, according to the table that we saw,
00:22:36
then he will do first L2 + L3,
00:22:38
and test whether the sum between the two is greater than L1
00:22:42
I also have to take the tests
00:22:44
between L2 is greater than L1 + L3
00:22:49
And also you have to know if L3 is smaller than L1 + L2.
00:22:55
A triangle can only exist if all these operations result in a true logical value.
00:23:02
We will show here
00:23:04
Escreval "can form a Tiângulo?"
00:23:09
we'll see whether or not
00:23:12
with the amount of IRT
00:23:14
Let's do some more tests
00:23:16
if I put 2, 2:02,
00:23:19
It can form a triangle, it forms an equilateral triangle and does not form a scalene.
00:23:25
Another test:
00:23:26
That 2, 3 and 4 we saw earlier,
00:23:29
it can form a triangle, not an equilateral triangle, but may form a scalene triangle
00:23:36
Let's do one more test:
00:23:38
That our 2, 2 and 3.
00:23:42
it can form a triangle, but it can not be equilateral or scalene
00:23:46
this because it is an isosceles triangle.
00:23:49
Finally, let's do a test with 2, 2:05.
00:23:54
2, 2 and 5 can not make a triangle,
00:23:57
because 2 is less than + 5 2 7 which is
00:24:00
2 here is less than 5 + 2 that is 7,
00:24:03
5 but it is not lower than 2 which is 4 + 2.
00:24:07
Then the third side would be too large to form a triangle.
00:24:11
So, in the case here, the logical result would be, he can not form a triangle,
00:24:15
It can not be equilateral and scalene less.
00:24:18
And then you can ask me, "But Guanabara, we have two equal sides and 1 different,
00:24:22
it would be isosceles right? "
00:24:24
No! Because of 5, 2 and 2a can not form a triangle,
00:24:29
and we see that for this result I just mark
00:24:32
You get the idea? We will return to this our reasoning about triangles,
00:24:36
later, when we go see relational operators
00:24:39
But for now, our time is up, and we'll have to leave for our next class,
00:24:44
that only comes out next week. In the next lecture I will show a new tool, in addition to VisuAlg,
00:24:49
it is much easier for you to learn algorithms.
00:24:51
But it is not so professional.
00:24:54
If you downloaded the package here in www.cursoemvideo.com,
00:24:58
surely you already have the Scratch application. I do not know if you have already installed.
00:25:02
Install as the next class we will use it,
00:25:05
and you will see that you will have great fun with this tool,
00:25:08
And will, break, learn a lot of Logic Programming.
00:25:11
Again I wanted to ask first: Practice!
00:25:15
Second, work with the course of the project in Video.
00:25:18
By clicking here, you sign the channel and will receive all the information whenever you have a new class,
00:25:23
Side button "Sign" has a gear,
00:25:26
click it, and say you want to receive an email whenever you leave a new class, so you will not miss anything.
00:25:31
By clicking here, you will watch all algorithm course lectures so far,
00:25:36
so if you come now, it is welcome, but you have some previous classes,
00:25:40
to be able to understand the construction of algorithms, and I recommend you click here and watch them all.
00:25:45
Do not forget to always share classes give Joinha in the videos,
00:25:49
Share to your Facebook, get there on Facebook and tell your friends pros: "Look!
00:25:53
Watch this lesson here. learn to program! "
00:25:55
We are here in the first steps to building algorithms,
00:25:58
and surely you will learn how to program.
00:26:01
I'll show various tools, I will show several techniques,
00:26:04
I will always teach you a rhythm a little more well cadenced,
00:26:09
for you to understand algorithms, for you to build algorithms.
00:26:13
Up to me to teach you, and I'm doing my part.
00:26:16
It depends on you learn, for that you need to practice.
00:26:19
Never forget. Study hard, a big hug and see you soon!
00:26:25
Hi! Someone came clattering hell.
00:26:29
I said fighting with you! Alas, alas, alas!
00:26:32
I really wanted the phone that damn who is calling at 8 am inside the company!