[no audio]
Friends, here
We are going to discuss the first two operators of your Python.
They are arithmetic and assignment operators. First
let me go with your arithmetic operators.
See we have different types of arithmetic operators.
They are like, you know already we know in your mathematics -
addition, subtraction, multiplication, division, modulo.
Right. So here floor division is somewhat a new one,
we will see that, and then exponential. So these all are
your arithmetic operators, right.
Let me open my Python terminal. There
I can easily explain about them.
[no audio]
Let me enter into my Python terminal, Python command line, or
Python Shell.
So guys, directly I can do suppose 2 + 2,
I mean any number you can take, not only 2 + 2, some
4 + 2, right.
So this is just to perform addition of two values.
Right. So I can store this result into some variable as well.
Let's say 'result=', or we can take any variable, addition
of two numbers, something like that or simply 'sum=',
or 's='. Variable is your wish, right. Now just print your 's'.
Yes, you are getting. Right. Not only like that,
just you can store your values in some variables.
And let me take 'c= a + b', and then print your 'c'.
So likewise, you can do your subtraction, multiplication, right?
Let me do one thing, 'c = a - b'.
So 'a' is 4, and 'b=8', the result is -4.
Now let's say 'c = a * b'
Now 'c' is 32.
Right. Now, let me do one more thing 'c=
if I take 4/8, right result is 0.5.
[no audio]
You know, right 4/8 result is, otherwise you just
do 8/4.
Then see the result, 2.0.
Okay. See guys, by default you are getting your result
in terms of float.
So this is with your Python 3, but if you go with Python 2
if any one of the value is
[no audio]
float, then only
you will get result as float number.
Right. Anyway, we are working with Python 3.x, right and we
know this is the future version.
I mean from 2020 we have to use this one, right. Fine.
Now, let me do, don't worry about this line guys.
Just I am going to clear my screen.
[no audio]
Fine. Now, exponential. Suppose if I want to find something
like 3² or some 4³, how you can find.
See 3², you can write 3**2. Now this
is nothing but 3². The result is 9. Of course, you can
store your values into, let's say 'a=5', and
'b=3'. Now if I want to find a^5, a*, sorry
a^b or 5³
[no audio]
or 5³, right, a³.
I can do either in this way or this way.
Just after the result, 125.
I can store that into some variable called 'result', or any
variable. Let's say, a**b. Now simply print your
'result', and see the value.
[no audio]
Right. Now if you observe we covered all the operations,
yeah, we have pending with modulo and then we'll see
floor division. So modulo.
Let me take some number guys. Suppose
I am going to take some 7, if I want to divide this with
2. 2*3, just 6. Now
what is the remainder value, 1. Right. Now see what I am doing
is 7%2, result is 1. Likewise suppose if you
divide 8 with 2, then what is the remainder?
So 8%2 is always 0, we know that.
Just to find your reminder
you're using '%' symbol. Then the last one is
floor division, right. See that. Right. Nothing is there. Just take two
times your '/', or division symbol. See the result. 4, right.
Now what I'm doing is, now see the 'result'.
By default if you take 7 by 2 what you were getting, 3.5.
If you do floor division,
[no audio]
right, if you do floor division. See,
yeah, simply assume that in this output only, in this explanation
two threes are six,
[no audio]
reminder 1. Your quotient is 3. You
will get this pure quotient without your floating points.
Right, and that too you can assume 3.5 actually, no. 7/6, or
if you do your 7
reminder 2. What is the value?
Sorry, 7/2, what is the value? 3.5. Then if you round off
that value to lower value then the result is 3. So that
is what you are getting.
[no audio]
Let's say 9.
Let's say -9//2.
See what you are going to get. You're going to get -5
because 9/2 is almost 4.5, -4.5.
Right. See in your number system
this is -5, then -4.
So compared to -4, -5 is the lower value. Now, whatever
the result you are getting for that result
you are getting round of value that to lowest round of value.
That's why I -4.5 round of value as a lower value is
always -5. That's what you are getting here.
So that is the uses of your floor division.
[no audio]
Right. Fine.
Then next one is, assignment operator. See already
we know one of the assignment operator like if I
write 'x=2', what you are doing?
[no audio]
2 value you are assigning to 'x'.
[no audio]
Okay. Suppose I can do 'x = 2 + 4', then guys
whenever you have a '=' symbol here, '=' operator here,
for this '=' operator always the right side whatever you
have that expression will be evaluated first,
then that result will be assigned to 'x'.
See, whatever the expression you have with the help of '='
symbol, let's say 'x=3x + 2'
[no audio]
Assume 'x' equals to some 3 value.
So your Python don't bother about here 'x' is there, here 'x'
is there. Your Python don't bother about that first.
It will take '=' symbol, then it will forget about this.
Whatever is there on right side, first that value will be evaluated,
and that result will be assigned to this variable.
So 'x' is 3. 3 * 3, 9. 9 + 2 is 11. 11
will be assigned to 'x'. If you want to get that result from your command
line, let me take 'x=3'. Then I am writing
'x=x*3', or '3x', '+', some 2. Now see the result 'x' value.
11, right?
So that is simply assignment operator or your '=' symbol is
basically an assignment operator, but see whenever if you
write 'a=a+b',
[no audio]
and observe that here 'a' is there, here also 'a' is there. So in this
case instead of writing your expression, lengthy expression,
you can also write as a shortcut expression as in this way
'a+=b'.
[no audio]
Not only for this, if you observe
all these things, right, see 'a' is there, 'a' is there, 'a' is there, 'a'
is there, so on both the sides for your '=' symbol whenever
if you have 'a', right, then at the time what you
can do is just remove this 'a', and then write '+' before
your '=' symbol.
Right. That's what I did here.
[no audio]
Now these both, two expressions are going to give same result.
So if you want to get the proof just open your terminal.
So here let me take initially 'a=' some 2, and 'b='
some 3 value. If I write 'a=a+b', what
is the result? Just observe that. 5. Now, I am going to reassign
'a=2', and then 'b=3'.
Now, what I am doing is 'a+=b' and see the result.
That means if you write
either this expression or shortcut expression both will give
same result.
[no audio]
Right. So these are all the assignment operators, and about your
arithmetic operators as well, okay.
Okay, and one more thing, so guys, suppose if you want to define
a simple arithmetic calculator.
Let me do it here.
[no audio]
So I am going to design simple arithmetic calculator with
the help of only addition symbol for time being because you
can perform any operation, for time being
I am going to create only addition arithmetic calculator,
okay, otherwise simply
'addit_cal.py'.
[no audio]
Just observe here guys.
What I am going to do is, suppose if I take 'a' equals to some 3,
and 'b' equals to some 5, and I want to find the 'result', 'result='
nothing but 'a+b', and I can print, using 'f' string
I can print
"The addition of and =", or "is ". Right. See guys, if
this is your Python Script or Python program in this you
have four lines.
See for any line if you observe there is no space at starting,
that is the rule of your Python, that is the basic rule for your
Python, don't provide a space before starting any line until
and unless if there is any special requirement for that. As
of now all are normal lines, straight forward, straight lines.
Right. That's why I'm not giving any space before starting your
any of the lines.
Right. And whenever if you run, your Python will run your program
from top to down line by line.
[no audio]
Then what is the very first line? 'a=3'. That means
somewhere in memory 'a' value will be assigned as 3. Same
way 'b', then 'result'. You know 'a + b', is the addition. So
'a' value is 3 and 'b' value is 5. 3 + 5, 8, you are assigning to
'result'. Then you are printing those values, right?
That's what we are doing here.
Now let me save it and run it.
[no audio]
So I am going to save it, and you know how to run your Python
script or program from command line,
simply your python interpreter space your program name.
That's what I am doing here.
See, "The addition of 3 and 5 is 8", you are getting.
But if I run this program again, and again, I am going to
get same result. If it is addition calculator it should not
give the addition for fixed numbers. Whenever if you are running
that script, that program it has to take two values minimum from the user.
You know whenever if you want to provide input for your script,
you have a command or statement called 'input' in your Python,
in Python 3.x.
Let me open our script.
[no audio]
See here, instead of fixing my values to 'a = 3', and
'b = 5',
what I am going to do is, let me comment these two lines. Now
'a' value read from 'input'.
So 'eval' is used to evaluate your given value.
So "Enter first number". So this is just info you know already
about your 'input'. Then same way
I want to get 'b' value from 'input'. So
'input(Enter second number")'
[no audio]
That's it. Right. Now
let me save this and see your code once whatever you have.
Right. So guys if you
observe here, first two lines are commented, that means
your Python won't consider those two lines as your Python
program lines.
[no audio]
Now very first line is this one.
So whenever if you run top to down, you know that, the very
first line is 'a=2'. We know whenever there is an
'=' symbol, that is an assignment operator. Whenever if you
have an assignment operator, assignment operator will try
to get first right side value, whatever you have.
Now, in right side you have some syntax,
this is helpful to read something from command line.
So whatever I am going to provide on command line that will
read by this expression and that value will be assigned to
'a' by your '=' symbol, or with your assignment operator. Right.
Let me run our code whatever we have. See that, "Enter the first
number". I am entering number 6, suppose. Then immediately in
the second line, right, you have once again "Enter second number".
And so because of this "Enter first number", I am entering
6, then I'm going to press 'Enter' on my keyboard so that
this 6 will go and store into 'a' with the help of this expression,
this syntax, right. Then immediately in the next line
we have "Enter your second number".
I am going to enter suppose something number called 9.
That's it. You're getting 6, 9, "result is 15". Now,
your program is like, you know simple addition calculator.
[no audio]
Right.
[no audio]
But after doing some advanced level concepts you can
design a simple arithmetic calculator with your Python, that
means addition, subtraction, multiplication, division, modulo,
floor division, whatever the operator, whatever the operation
you need all those operations
you can do with the help of your Python scripting. So for
that you need to include some logic, before including some
logic you should know some concepts. We'll discuss that concepts
first, and then we will once again design a full-fledged
arithmetic calculator with help of
your Python Scripting. Okay, for time being this is very simple
one. Okay, so guys here we discussed about arithmetic operators
and assignment operators, and also how to read any two numbers,
and then how to find addition. The same way
you can try for your addition, subtraction, multiplication,
division, modulo, floor division, and exponential. You just try.
Write a separate Python Script for each and every concept
here whatever we have.
[no audio]
Right. Fine.
Okay guys, thank you for watching this video.
[no audio]