Calculator - Our first project

Calculator

Now, after learning so much, we are going to write our first real program that is a calculator. So, let's get started.

What will be the final output?

Som what our code will actually do is that first it will take two inputs that are the two numbers that the user wants to calculate and then the code will perform all the four main math operations i.e addition, subtraction, multiplication, and divide on it and then tell the result.

Step 1: Taking input from the user.

The first thing that we need to do is to take input from the user which is very easy to be done. We will be taking two inputs that will be the two numbers and then we will store them in two different variables for further operations.







Step 2: Convert into Int type:

To perform mathematical op erations on it, we first need to convert them into Int type as by default they are in string type. So now we need to use the int() function.






Step 3: Doing the maths:

Now let's perform the main four mathematical operations on it and save them into variables. So, we will do +, -, ÷, × on the two numbers.



(replace // with a single / for accurate answers)


Step 4: Presenting the results:

Now, let's show the results to the user with the print function with some string concatenation in it. We will present such a way that the user should understand which result is for which operation.






Step 5: Our whole code:

So our whole code looks like this:-













Step 6: Beautify the code:

We are going to do some small changes in the code and you have to figure out what are they and why these changes are good.












Our calculator is ready but we will be updating it as we learn new concepts and implement them in our code.

What next?

Now, after making this awesome calculator we will be moving towards learning string slicing.

String Slicing

Comments

Popular posts from this blog

Comments

#1- Let's Learn Python In the least possible time

#9 - String Concatenation