Oh yes and welcome back to another class of our course about Python.
So in our last class we practiced a little bit what we have just learned.
Until now in this class we are going to do the same thing.
So we will create another Python up this time a bit more complicated but just using the notions that
we learn until now.
So we are not going to add nothing new.
We're just going to use the notions that we learned until now.
So it's gonna be very cool.
My goal today.
Well the objective of this new app that we are going to do today is very simple.
So we will have three persons which will have each of them will have a name.
Those three persons will buy a pizza and we want to know how many slices each person eighth of the pizza.
And depending of the number of slice that each person eight will give a will.
Find out how much each person will pay.
So we'll write down the code for all this and we will go step by step.
I'll explain you how all this.
Well how all this will work.
So let's start.
So the first thing I'll ask you guys to do is like always open up your text editor and going to your
project one.
So like you said the first thing that we want in this app is our user to give us his name his or her
name depending if it's a girl or a boy.
So we'll ask him.
We'll ask him to enter his name.
So we'll simply enter name one in this case and one what we want.
As I said we want the user to give us his name so we'll write down input.
That's the function that will allow us to ask the user for his name.
So in this case we ask the user for some things or write down input and the user will simply give us
his name.
So you write down and so input open up your very brand theses and ask the user what is your name.
That's very simple.
We did this for our first user.
So we will simply copy everything and pass them so we have.
Name one name to name three as I said we have three users.
So very simple.
We simply copy and paste everything.
All right.
So this is for our well the first data that we need to collect our names.
So in this case we have strings.
And the next thing that we want as I explained we want to know if we want to find out how many slices
each person eight we need to find out at first.
How many slices the pizza have.
So what we will ask our user is how many slices the pizza have.
So we can write down slices in the pizza.
So once again we ask our user How many slices is there in the pizza.
Let's not forget your input function and you ask your user How many slices in the pizza.
All right.
So right now that we know the number of slices in the pizza.
We want to know what is the price paid for the whole pizza.
So what is the price paid for all the pizza.
So in this case if the pizza cost ten dollars and one user eat only one slice of well if the pizza cost
ten dollars and there is ten slices and the first user only eight one slice this means the first user
will have to pay one dollar so we'll do it this way.
So as I said the next question is what is the price of the pizza.
So we have no slice.
We have the price.
So once again simply write don't input and we ask our user what is the price of the pizza.
Great.
So we have our first data right here we have the names we know will we know how many slices there is
in the pizza we know what is the total price of the pizza what we need to know right now is how much
each person eat.
So in the first case how much of the pizza of the whole pizza the first person eight.
So let's say the first person eight 50 percent of the whole pizza will ask the person how many how many
parts or how many.
Let's say what percentage of the pizza have you eat.
So once again we need to put this into our code.
So how we'll write it down is very simple.
I will write down percentage
8 by
person 1
so in this case we have our variable percentage aid by person 1.
We can name it like this if you want to make something shorter.
Well you can ask once again to ask our user what percentage he ate from the pizza.
So write them so will once again write down input.
So we will use our variable name one as a reference because we are talking to the name one so the first
user in this case we are talking to this person.
So we'll write down name one and we'll ask this person what part of the pizza.
What percentage sorry.
What percentage of the pizza do you have.
So once again why I use the this variable right here as I explained when we'll print everything and
went Well when we won we will ask our question to this person to the person that I have named one one
a name this person so want to ask this person.
So to ask this person and to know her name or his name we need to refer to name one.
So in this case this variable we need to refer to this variable so we do this for the person number
one.
The next thing that we need to do we do the exact same thing for the person number two and the person
number three.
So you can simply copy and paste everything and when it's all done you simply change the variables so
well the variables the numbers.
So in this case we have Person 1 here we'll have person 2 here will have a century.
Same thing for the names.
So we have named number two.
Name number two.
So I hope you follow until now and you understand what we are doing.
So let me just summarize what we did until now.
Since it's not done we named our so we have our first variable which is name 1 2 3.
We named our users.
After that we find out find out the total number of slices and the pizza.
The price of the pizza.
And right now we are looking at how many.
What percentage of the pizza.
Each person.
8.
So very simple.
That's the data that the people will have to give us.
So we will be able to calculate everything good so we have all the data that we need.
Now we need to make the calculation to be able to answer to our questions.
In this case we want.
What are the questions that we want to answer to.
The first one will be how many.
Well how many slices the each person have.
Eight.
And the second question is what price each person paid for the pizza.
So to find out.
So we'll write down a number of slices
this will be the first thing that we will look for a bi person.
So this will be our variable that we will use so the calculation to find out the number of slices by
the first person is very simple.
We simply multiply the percentage of the pizza that the person have 8.
So in this case of the person have a 50 percent of the pizza will multiply 50 percent by the number
of slices there is in the pizza.
So in this case if there is 20 slices in the person 8 50 percent of the pizza we will have the person
number one will have 8 10 slices.
So it's very simple.
So how do we calculate this.
We want to multiply right here the percentage 8 by person number one by the number of slices but very
important since all all the data is stored in strings.
The first thing we have to do is to transform this data into numbers to be able to make the calculations
so we will use the float function for this.
If you guys remember so the float function is really used to transform strings and strings into numbers
and the function.
The function SDR is used to transform numbers into strings because we can't work with strings and numbers
at the assembly so both data will not work together.
So write down float and simply go and look for our first viable which is percentage 8 by person number
1.
So here we go.
We have this and the calculation will be percentage 8 by person number 1 multiplied by once again float
because we want to transform our slices in the pizza into a number.
Right now it's a string so we'll write down float and we'll write down slices in the pizza.
So this is our first calculation that we want to do.
So this calculation will help us find out the number of slices that the person number one have 8.
So when we have this we need to find out the same thing for the person number two as well as the person
number three.
So simply copy and best everything and then you can just change the data.
So we have a number of slices made by person number 2 and person number 2.
So you can just change the numbers the slices in the pizza stay the same like always.
So when it's all done right now we have the calculation that will help us find out the number of slices
that each person eat.
The next question that we will ask ourselves is what is the price paid for by each person.
So in this case let's say each person have.
If a person have a 10 slices of a pizza 20 slices and the price of the pizza is 20 dollars.
Well the person will need to pay ten dollars because each slice costs one dollar so there is more than
one way to find out this answer.
But the way that we are going to use will simply multiply.
The price of the pizza and the percentage of the pizza 8 by the person number one by the price of the
pizza.
If the person number one have a 50 percent of the pizza person no one will pay 50 percent of the price.
So how do we do this.
Very simple will create another variable that we will name price paid by let's say number one.
So in this case.
Name one.
Let's say name one price paid by name one and we write down this.
So as I said the calculation will be the percentage of the pizza.
8 by person number one by the price of the pizza multiplied by the price of the pizza.
So once again we'll use our float function and we'll simply multiply.
As I said percentage.
So in this case we will calculate will refer to the variable percentage aid by person 1.
And all this multiplied by once again the float function.
The price of the pizza as you can see this is the calculation.
So this calculation will help us find the price paid by the person number one so when it's all done
it's very simple.
We simply come back here and we copy and fast everything
and then the next thing that we will have to do is just change the numbers.
So in this case we just changed the number the name one by name two.
And same thing for the percentage eight by each person as you can see it refers to this percentage end
to this percentage as well.
All right.
So right now we have all the calculation that we need for our app to work.
So the next thing that we will need to do is print everything.
So what exactly the person will have as an output.
So those are our inputs.
This is the inputs.
That's what we ask from the person.
This is what the app will do like calculation.
So those are the that's the calculation part.
That's the first part.
That's the second part.
And the last thing is what will be the output of all this.
So very simple.
What we will print will be the person number one have eight a certain number of slices and have paid
a certain price for his meal or her meal.
So let's write it down.
So name number one in this case have eight.
So you open up your small commas and write don't have eight so forget to add spaces because in the other
case you'll see it's not gonna be very very beautiful.
Then the next thing we'll have eight number of slices.
So the number of slice in this case is a number so we need to transform this number into a string.
If we want our app to work so simply write down s t r so the function SDR and we ask for the number
of slices a by person number one.
So as you can see that name so the person number one this case have eight a certain number of slices
then we'll continue our function a function our output
so I have eight this number of slices and have paid have paid how much.
So in this case we'll do the exact same thing.
We'll return the string of the price paid by the person number one so we'll go and look for the variable
price paid by name one and we'll continue dollars for his meal.
All right so let's put everything together.
Let's the critics eat everything.
So what is our output in this case.
The output says name number one.
So this variable which will be our first name have eight.
This will be the number of slices and the person number one have eight.
So we need this answer and have paid.
Right now we have our second half paid.
This is the price that the person have paid.
So in this case we'll return this variable right here and this is just string.
So this is just text dollars for his meal.
So as I said very important don't forget to add spaces because in the other case it's not gonna be very
beautiful to look at
all right.
So until now we have everything that we need.
We have the output for the person number one so what we need to do right now we need to write the same
output for the person number two and the person number three.
So how we will do this how we always do.
I will simply copy and paste everything in the next sentence in the next line of code.
So a simple simply select everything that you have here and you passed it on the lower line of code.
All right.
So when it is done simply change the numbers.
So in this case and they will be named to end name treat and the number of slices eight by each person
in this case person number two person number three.
Same thing for the price paid for each person by each person sorry Here we go.
So right now we have the whole code completed for our app.
Let's run everything and see what it all looks like.
So in this case if you want to run everything simply click on the run.
So the app ask us What's your name.
In this case let's say it's Mark.
So name or no one will be Mark.
Name number two will be.
Let's just fix one little thing before we continue so just add two points so it will be more beautiful
when you write down the names once again.
It's not an obligation if you just want to run the app right now.
You can run it.
It will still work but just to make it more beautiful you can add the two points.
All right great.
Let's run the app once again.
Good.
So what did it.
What is your name once again.
As I said it's Mark the same name let's say it's going to be John and the last name will be let's say
I don't know a little.
Here we go.
How many slices in the pizza so let's say the piece that we had 15 slices let's say 16.
What is the price of the pizza in this case let's say the pizza have custard for you dollars what percentage
of the pizza you have eight.
So in this case Mark we forgot to add a a space.
So once again as you can see it's not beautiful when you don't add a space we can just add spaces.
So it's not a big deal.
The Apple Store.
So what percentage of the pizza you have.
So Mark have a 50 percent.
So we'll not write down 50 percent like this.
We'll write down 50 percent like this zero point five this week by 10.
We'll be able to calculate everything John.
What percentage of the pizza have you 8.
So John have a twenty five percent so we'll write down zero point twenty five.
And Eileen what percentage of the pizza have you eat.
We'll write down zero point twenty five.
So once again twenty five percent then we'll simply click on enter.
And as you can see this is our output.
So Mark have eight eight slices and have paid twenty dollars for his meal.
John have a four slices and have paid ten dollars for his meal and I have a four slices and have paid
ten dollars for her meal.
In this case her meal.
So as you can see the app works perfectly everything is amazing.
If you want to make it more perfect and you want to change some things you can just play with the text
maybe.
For example right here in this place Mark instead of as you can see it's it's well it's together what
you can do is simply add some spaces.
So it just a question of spaces and you'll see everything will be more beautiful and more presentable.
Same thing for example right here when you guys.
Well that's it.
That's nice.
Oh yeah.
That's it.
Right here for example Alan since it's a girl you can write down for his her.
So let me just show you the radar right.
I don't like this or his or her view and that's it.
So the app will still solve right now the upper it's perfectly the only little fixes that you can do
well I just told you we can do as a fix.
So right now guys we just put everything together.
What we have learned into practice so I hope you like the course so far so as you can see programming
in Python is not that hard.
So we created a code that is a bit more complex but just with the things that we learn until now no
new functions.
Right.
So that's it for this class guys in C all in our next class.