Python Calculator
In this blog we will be learning about how to make a simple and our own calculator.
In the end I will give you my github repo and the link for idle and visual studio.
So, lets start coding
Step — 1: Get the user input for the first number in the equation
#First number input
num1=int(input("Enter the first number: "))
The “num1” is the variable which stores the value of the first number in your equation.
Step — 2: Get the operator input
#Operator input
op=input("Choose the operator: ")
Here “#” stands for the comments.
Comments are those lines of code which is ignored by the compiler while running the code. It helps the reader of the code to understand the code better.
Step — 3: Get the user input for number 2 in the equation
#Second number input
num2=int(input(Enter the second number: ))
Here “int” stands for the number input whether it is a negative or a positive number.
Step — 3: Define the operator. I will define all the operators alltogether.
#Addition operator
if op == '+':
print(num1+num2)#Subtraction operator
elif op == '-':
print(num1-num2)#Multiplication operator
elif op == '*':
print(num1*num2)#Division operator
elif op == '/':
print(num1/num2)#Floor Division operator
elif op == '//'
print(num1//num2)#Floor Multiplication
elif op == '**':
print(num1**num2)#If the user get another input accept from the above lines of code
else:
print('Get a valid input')
That’s all for today….. Will meet in the next blog…
SHREEVATSAN SAKTHI My friend
My second site in which I write some of the python tutorial and many more things Divyendra Rajawat
My github repo
Link for python IDLE
Link for Visual Studio
Link for pycharm Pro and Pycharm Community edition
please subscribe these