Well yes and welcome back to another class of our course about Python.
So until now we saw a lot of very interesting things.
And we talked about strings with about numbers we talked about many many things.
So until now you have a small base about programming.
And in this course we are going to put everything together.
So this way we'll see well you will be able to see what you can do with all this knowledge.
So once again we are going to create a small app just to put everything together.
And we also will learn a new function that will be very important in our app creation.
So basically let me put you in context.
We are going to create a app that will calculate the products that we are going to buy.
So let's say for example we buy will buy in this case tree products want to calculate the price of the
product and the quantity.
So want to know what is the price of each product.
Want to ask our users.
I want to ask every user what is the price of each product that this user will buy from us.
And what will be the quantity of each product that the user but will buy from us.
So let's say you will buy five products the price of each product will be in this case 20 dollars and
the quantity will be five.
Well in this case once again.
So how do we.
Will we read this.
So the app will be divided in some parts.
So the first part is write down the variables that we will need to have.
So as I said we will need to know the price of our product so we have the price of the product one and
the quantity of the product one.
All right.
So we have this.
But as I said we have three products so we select those three lines and simply copy and paste it then
you simply write down product to quantity product to.
You can do the same thing for the third product.
As you can see we have our cheap products right here.
So those will be the variables that we are going to use for this app that we are going to create as
you can see it's until now it's very simple.
Right now what we want to do we want our user to to enter a certain question.
So we will need to ask him a question.
So very simple.
We'll write down input.
So what exactly we are going to ask our user what we'll ask him.
What is the price of the product.
One so in this case he will answer us.
What is the price of product of the product.
One
and the same question will be once again input since we are asking our user
another question.
So what will be the quantity but so what will be the quantity
of the product.
One so until now we have our two questions.
So you get the point for the second for the second and the third product will do the exact same thing
so you can just copy everything right here and you can test it for the second product and for the third
product as well to simply copy and paste everything.
All right.
When all this is done
it should look something like this
meaning.
So right now we are we have our small database.
That is where we only have six things.
So some products and quantities.
Next thing that we want to do we want to calculate the price and the quantity.
But we have a problem.
You understand that since right now we have our price our quantity.
But if we if we calculate the price but we multiply the price by the quantity it is going to give us
an error since by different since.
Because by default Python generates a string as an answer.
So for example if.
Right here I write down 5 as an answer a python will generate 5 in a string not as a number and we can't
make calculations with strings.
We need to transform them into numbers.
So how exactly we will do this is very simple.
So let me just show you what it looks like at first.
So we need we will have result
product 1 so that that's will be that will be our next table.
So the result of product 1.
So it's gonna be
price product 1.
So in this case the calculation will be price product one multiplied by
quantity product one
so we're important guys we need to write the exact same thing that you wrote higher.
So right now I had the mistake because here I had the mistake
so if you have a mistake where your code doesn't work it's because it's because you just did a mistake
right.
So right now you have your result for the first product to let's look what our app looks like until
now so the price for the first product will be let's say 10 and the quantity of the first product will
be let's say 2 for the other products we don't need to make calculations.
So we generate zero.
So as you can see right now we have an error.
So why as I explained here we don't have to do those those first variables.
The answer is generated in a string.
So this means it's generated as a text and we can make calculations with text.
So what we need to do we need to transform those variables into two numbers.
So just write two points to make it more beautiful.
Once again the two points are just for better representation.
All right.
So what is how exactly can we transform those string.
Those Well the strings that will be here two of those variables in two numbers so it's very simple.
We'll use a function that is called the float function.
So simply write down float
and you can do it for the same variable as well.
Great.
So right now we have our float function in front of our quantity and our price product but so if we
rerun the up and once again we do the exact same thing.
So 10 2 and that will write down 0 just because we don't have those calculations
so right now this will give us the answer
we forgot to print.
So so we print our answer in this case result
product 1
and we can run it once again.
So 10 2 0 0 0 0 so you can see the answer at the end is 20.
All right so you get the point.
Very important to use the float function.
So we have the result for the first product right now we need to do the exact same thing for our two
other product.
So what we'll do.
We'll simply copy and paste everything here and replace the number one by number two since we named
our variables this way so price product to and same thing quantity product.
So very important you need to verify if your price is linked to the right product at first.
So product 3 do the exact same thing
great and the same thing for another three.
So right now we have everything we need.
We did our first step which is asking the person for the informations making our first calculation and
the second and last calculation that we need to do to be able to generate our result will be simply
the addition of those three results.
So the addition of results.
Product 1 result product 2 and result product.
So how exactly will do this.
Will write down the exact same thing so result
will be equal to once again
result.
Product 1
plus
result product 2 plus result product 3
so you can see right now we have all our we have our complete calculation.
So we want to do right now we want to print our result.
So that's exactly what we'll do.
So we are going to print our result
so we just run the app.
So the price for the first product let's say it's gonna be three ninety nine.
The price for the second product let's say it's gonna be twenty five the the quantity sorry the price
for the second product will be for sixty seven.
The quantity will be to the price of the third product will be let's say nine eighty five and the quantity
will be six.
And at the end as you can see the final price is one hundred and sixty eight one hundred sixty eight
dollars and 19 cents.
So as you can see right now we have everything that we need if we want to transform our result into
a string.
It's possible we simply can write down SDR and this will automatically transform our result into a string.
If for example we want to make something that is more cool let's say for example we can write down your
final price is something like this
and since you can't work with numbers and strings you need to transform your result into a string.
So you simply write down as.
And it should give you the right result.
So in this case we can write down what is the price of the product let's say twelve.
Quantity three then so we just enter Wyndham numbers to see if it works.
So we are testing the app and as you can see your fight your final price is one hundred fifty six dollars
to just add a little space right here.
So as you can see right now we put it in application everything that we learned in the past courses
and we created a small app that is able to calculate our groceries or adjust our products.
So if you guys don't understand this let me just summarize everything that we did so you'll see it's
going to be very very easy.
So the first step.
We created our products and our quantities so we created our variables and we asked our user to enter
the price for each of them and the quantity of each of them.
So when the user is entering all this the second step that we want to take we need to take is to calculate
all this.
So how exactly will calculate it.
Very simple.
So the result of the first product we find out the result of the first product the result for the same
product and the results for the third product so this are this is the first calculation that we will
do when this calculation is done we still need to do another calculation which will be to find out the
final result.
And in this case the final result is simply the result two plus the result the result one plus the result
two plus the result two.
So this is our final calculation and at the end what exactly we want to print to our user.
So what exactly want our user to see what our user to see this.
So this is our answer so we want our user to see your final price is resolved.
And why exactly we wrote stream here.
It's because if we don't write SDR our final result will be in numbers and we can't work with strength
in numbers at the same let's say at the same set in the same sentence or in the same line of code.
So it's very important for you guys to transform this the number into a string so I hope until now you
understand everything.
So as you can see we've built up our first small and basic app and yeah it's not something that is that
hard.
So as you can see Python is not very very hard.
It's just a question of practice.
So I hope you guys liked it and that's it for this test.
And C O in our next class.