It isn't.
Welcome back to another class of our course about Python.
So in the best class we talk mostly about strings how strings works and well what are strings.
And in today's class we are going to talk about another type of data which are numbers.
So my goal today is to show you how works.
Numbers what exactly we can do with numbers on pythons.
And we are going to talk about some basic by ton functions and how to use them will also integrate the
numbers with the strings since we did sell how to do it in our best class.
All right.
So let's begin.
So before we start you guys need to understand that in Python to have access to well to all the math
functions you need to write a simple line of code.
So this will give you access to all math functions.
So simply write down from math import and you write down this little star when it's all done you are
able to write down all the math functions that you want.
And trust me in Python you have hundreds of different math functions.
And my goal here is simply to show you what to give you an introduction to all of this.
So let's start.
All right.
So you have different type of numbers that exist well in everyday life as well.
So you have complete numbers let's say forty five is a complete numbers.
No you have negative numbers.
So minus five forty forty five and you have the numbers with the commas in this case twenty six point
three to one.
So those are the numbers that we will work with in Python.
So the first thing that we are going to do is make basic calculations.
So in this case we are going to talk about addition multiplication division and subtraction.
So how all this works.
Very simple.
So if you started the same way you write down print you open up your parentheses and let's say you want
to do 10 plus then you simply write it down like this and you can run your code as you can see the answer
is 20.
So Python gives you 20 as an answer.
Same thing if for example you do 10 plus 10 multiplied by three.
So what school with python is that it will respect the priority of operations.
So it's like a calculator for example you do 10 plus 10.
In this case it's not gonna do 20 multiplied by treats going to multiply three by 10 at first then do
plus 10.
So this will return us 40 which makes sense.
But let's say for example I want to do 10 plus 10 at first.
So I'll simply need to enter my vertices and then I run my app.
So as you can see my answer is 60.
All right.
Right now let's say I have more than one operation.
So I have all those operations I have additions that have multiplication I have division and I have
let's say subtraction.
So all this very important.
If you don't have the right amount of parentheses.
Python was simply not to run up.
So very important to have the right amount of parentheses as you can see right here is the answer to
my calculation.
So as I explained python is really a huge well it's also can be used as a huge calculator and you have
access to all the mathematical formulas in it.
All right.
So this is to understand how to make basic calculations in Python.
Next thing that we will before we continue.
Just give you a small difference between numbers and strings and the way you'll write it down.
So let's say you want to print a number so you will simply write down.
Well let's say when the print is trying so you will write down print open up your your commas and let's
say you want to write down a word.
So just a word you'll print it and it's going to return you word if you want to print a number.
You don't have to write down those those those commas right here.
You just can write down your number in this case let's say it's 20.
202 as you can see right here you have your number which is two hundred and two if you write down those
commas.
It's gonna work as well but the only thing is it will not be a number.
And if it's not a number well it will simply not work as a calculation so let's say I want to add this
with the 20.
So it will not work because in this case you are trying to make an addition of a number with a string.
So it's normal that it's not working even if this will give you the same answer as this as you can see
it gives you the exact same thing.
But this is a string.
This is in number.
So with this you can't work you can make additions abstraction and everything.
And then with this it will work.
All right.
Let's say right now we have a string.
So in this case let's say we have print.
We have our.
Well we have our sentence.
So we have a small sentence which will be in this case.
Hello.
My age is twenty five.
So I have my sentence.
Just put it.
Perfect.
Right now let's say I want to work with my twenty five let's say when I store my twenty five into a
variable which is called age and we will store twenty five and this variable and then what I want to
do I want to integrate my age right here let's say I write down each
so in this case it's gonna look something like this
so what I just did.
I have my text here and I added age but since it's a string and a number we'll have a year right here.
It doesn't work.
So how you can modify this.
It's very simple.
First of all you can transform your variable right here which is a number into string.
So let's say I want to transform it into a string.
In this case it will work.
But let's say I want to keep it.
I want to keep this as a number because I want to make calculations or whatever I want to do with it.
So how I will do this is very simple.
I will simply add that I will simply work with a function.
In this case this will be a function that will transform my age into my age which is a number into a
string.
So in this case I will simply write down a star.
So as the bar will be this function and I simply close my burnt is when it's done.
So when we play our app it works.
So it gives us Hello my name my age is and in this case it's twenty five.
So you can see it works perfectly.
So this is a good way if you guys want to work with let's say a string if you want to work with strings
and numbers let's say for example and make calculations here.
It's gonna be twenty five plus then and in this case my age is thirty five.
So here I have two numbers that works together and I transform them into a string here.
So I'll be able to work with the strings and with a number that I transform in a string as well.
So right now you understand how this works.
So this.
Those are the basics.
Next thing that we are going to talk about will be functions that you guys can use with numbers.
So let's say for example you have a small database of numbers.
So let's say I would print I have 1 5 6 2 9 4 30 so I have all those numbers.
And from all those numbers I want to find out which is the highest number.
So what exactly I will use I will use a function I can use a function that will help me find out which
is the highest number with between all those numbers.
In this case is gonna be the max function.
So I just select all my numbers right here and I click on run my app.
And in this case the number that is generated is 30.
I can't have any type of numbers right here.
I can have.
Well I can have numbers that are negative numbers.
I can have positive numbers.
I can have any any type of numbers.
It will still work.
All right.
So this is for the max function.
This is a good way.
If you guys have a database of numbers and you want to find out the highest number or does well the
highest number with the max function next function we are going to talk about will be the main function
which is how to find out the smallest number possible in this case it is the main function.
So as I said the main function we want to do right now is simply write down men instead of writing Max
and you run your app because you can see here your smart your smallest number is minus 1.
So even if your numbers are very complicated so let's say you have zero point 2 1 3 6 and any other
type of numbers it will always find out the smallest number between all those numbers.
In this case it doesn't work because here we go right now.
Right.
So you can see you will always find out the smallest number between all those numbers.
So right now you understand how to find out the biggest and the smallest number.
Let's say you want to do a more complex calculation that integrates let's say making calculating power
power so let's say you want to do equal.
So print
five and you want five and that 5 Power 2.
So in this case is gonna give you twenty five.
So how do you calculate this.
It's very simple you have a function that will calculate the let's say well the.
In this case the power.
And in this case it will be.
Well this is the power so instead of doing this and this and you run it and it doesn't work if you want
to make this calculation it's going to be a function that will do it.
It's that power function.
And how do you calculate this.
It's a very simple the first number that you will have that you want is let's say five and you want
five in a power of two so you will multiply five by five.
So here we go.
We have our five and want to multiply five by five.
We run our function as you can see it give us twenty five as an answer.
Once again we can make our other calculations so let's say fifty five divided by thirty six plus the
power of five by you two.
And we run the app and as you can see gives us the answer and the answer makes sense.
All right.
So right now we know how to calculate all this.
Let's say we want to add another function to our calculation.
We want this number as a complete number.
So we want it.
In this case we want let's say instead of having twenty six point four four four four four we want to
have 26.
So how exactly we'll do this.
Once again it's very very simple.
We'll simply add a round.
So there is another function.
So we will be able to calculate well not to calculate but simply to generate that the number which is
the closest number to well the closest complete number.
So in this case 26 will be the closest complete number.
So it's very simple.
It will be the round function
and you can run everything.
So it give us 26.
So let me just explain what we just wrote.
We ask.
Excel Excel so we ask Python to run this calculation and to give us the round value well we ask Python
to print the round value of this calculation.
In this case we ask by down to print us the complete and only the complete number of this calculation.
In this case it's 26.
So if let's say for example right now we want if we have let's say in negative numbers or we'll just
write down minus all this and we'll run our calculations.
So as you can see our answer will beat minus 26 and let's say right now we want to have a positive number.
So we still want our twenty six.
We still want to have 26 but we have minus 26.
So how do we do this.
It's very simple.
We have another function in Python that is called the D A B A B S which will calculate the absolute
value of a certain number which in this case will be the absolute value of minus 26.
So how do we do this simply write down a b s open up your parentheses and you can close them and we
will run our calculation and as you can see you have 26.
Let me just give you a small demo.
What is the IBS function.
So let's say you have minus 20 and that you want to print.
You want to have the absolute value of minus 20.
It will simply give you the absolute value of minus 20.
And let's say you print it.
So as you can see here you have 20 which is the absolute value of minus 20.
Right here you will roll down a a bit complicated math calculation.
But once again it's not.
Well when we go step by step it's not that hard to understand.
Right now what we asked White on to do we asked Python to print the absolute value of minus the round
value of this calculation.
In this case as you can see it integrates all the functions that we want together.
Let's say right now we calculated the power of something but let's say we want the square root of something.
So in this case we simply will write down print s q far T and the one the square root of twenty five
is gonna be five.
As you can see it's down here so we'll just delete the first part of our calculation so once again this
is another math the math thing that you can do on Python as I explained you can do absolutely anything
on Python that you can do on the calculator.
All right.
So let's talk about some more advanced math functions that you can have on Python.
Once again you have hundreds of them.
But some variable some that are very very important very important but some that are commonly used in
just some basic ones that I found out on the Internet and that I think will be interesting to show you
guys that you can have on Python.
And if you want to have some others that you want to use you can just go on Google and write down Python
math functions you'll have well hundreds of them.
So let me just show you some basics that exists on well that you can use.
So the first one will be sale.
This function is very simple it will return you the smallest integrate integral value greater than the
number.
So let's say for example I write don't sell off in this case twenty three point nine nine nine nine
nine and I run it.
So it's gonna be twenty four.
But if I write down twenty three point 0 0 as a resume one it's gonna be twenty four as well because
we return well in this case the highest value after twenty three even if it's twenty three and an infinity
of zeros we will return 24 twelve not an infinity of zeros let's say enough zeros because if it's an
infinity it's gonna be too much close to twenty three.
All right.
So the next question is if let's say want to do the reverse of the sale function in this case we want
to return the greatest value.
So in this the first case it was the smallest value.
And in the next one to return the greatest value.
So it's gonna be the floor function.
So instead of sale we'll write down the floor.
So as you can see returns twenty three even if the answer.
Well even if our basic number is twenty three point 9 9 9 9 9 as you can see returns twenty three.
Another way to calculate Well we have the absolute value if we want to calculate the factorial of something
there'll be another well that'll be the last function that we'll see today.
The factory all of a function is simply a number and you multiply all the smallest numbers of this number
by.
Until you reach this number.
So let's say for example 5 the 5 defector you'll call de facto real value of 5 will be 1 multiplied
by 2 multiplied by three by four by five which indifference of the absolute value will be simply minus
stand will equal to ten.
All right so let's calculate the factorial of something in this case we will simply write down print
we open up our parentheses and write down factorial and let's say we want.
We don't want a big number at first let's say we just want the number three in this case the answer
will simply be six because we did 1 multiplied by 2 multiplied by 3.
But let's say we have a huge number which will be let's say one hundred which is really really huge
for rules.
Well in this case it will generate us the answer as you can see the answer is huge because with it one
multiplied by two by three by four until one hundred and we have our answer right here the more the
number is huge the more the calculation is going to take time.
I'm not going to make the allegation for a huge number.
I don't want my Python to bug but if you guys want want to try it at home you can do it just don't write
down two huge numbers because your computer will just freeze.
So this is for you.
This is for the numbers part.
So until now we saw all the not well we we talked about all different types of numbers.
We talked about the how to make basic calculations and by time we talked how to work with strings and
numbers and how to store both of them together.
So you should be able to do it on your own right now we talked about some basic math functions.
Once again if you are interested to find some other math functions you have simply go on Google and
write down Python math functions and you can have hundreds of them once again.
I just use those as an example because I wrote down Python math functions and I was able to.
Those were the most popular and I just showed them as an example.
But once again if you want more advanced math functions you can find them at the end of the day is how
you use them.
It's and it's not about the functions but it's how you use them and what exactly you make with them.
All right.
So until now you understand what our strings and what are our numbers.
So for this course.
That's it.
And see you all in our next class.