Calculator Program in Python | On Different IDEs

Calculator Program in Python On Different IDEs

Welcome to violet-cat-415996.hostingersite.com. In this tutorial, we are going to write a simple Calculator Program in Python and run it on different IDEs of python for creating a calculator we are using the mathematical operators, functions, conditional statements, and handling of user input to create our calculator.

In this tutorial, we are going to see the various python IDEs on which we are going to execute our calculator program.

What is an IDE?

An IDE i.e an Integrated Development Environment refers to a software application that provides extensive software development abilities to computer programmers. The IDEs increase the programmer’s productivity with the help of python edition features of source code, building the executables, and debugging. Most of the modern IDEs we come across have intelligent code completion features. Hence the IDE helps computer programmers to understand the various aspects of writing a computer program.

Calculator Program in Python on Different IDEs

So Let’s begin with our calculator program

Calculator Program using cmd

#Progran to perform addition ,substraction,Multiplication,Division
from sys import argv
print("The number of command line agruments :",len(argv))
sum=0
sub=0
mul=1
div=1
for i in range(1,len(argv)):
    print(argv[i])
    sum = sum + int(argv[i])
print("The addition is", sum)
for i in range(1,len(argv)):
    sub = int(argv[i])-sub
print("The subtraction is",(~sub+1))
for i in range(1,len(argv)):
    mul = int(argv[i]) * mul
print("The multiplication is", mul)
for i in range(1,len(argv)):
    div = div / int(argv[i])
print("The division is", div)

Explanation:

  1. Here we are going to execute our program by taking command line arguments. We are importing the argv from the system module where the argv is an array for the command line arguments in python.
  2. In the command line argument the first element of the array of sys.argv() is the name of the program itself.
  3. In this program, we are performing 4 different operations addition, subtraction, multiplication, and division for we are taking four different variables add, sub, mul, and div for storing the result.
  4. The len(argv) counts the total length of arguments.

Output

The output of Calculator Program in Python using cmd

Calculator Program in Python using Pycharm IDE

#Functions for addition,substraction ,multiplication,division
def add(x, y):
    return x + y


# It subtracts two numbers
def subtract(x, y):
    return x - y


# It multiplies two numbers
def multiply(x, y):
    return x * y


# It divides two numbers
def divide(x, y):
    return x / y


print("Select To calculate.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
    # take input from the user
    ch = input("Enter the choice: ")

    # choose from the four options
    if ch in ('1', '2', '3', '4'):
        no1 = float(input("Enter Number1: "))
        no2 = float(input("Enter Number2: "))

        if ch == '1':
            print(no1, "+", no2, "=", add(no1, no2))

        elif ch == '2':
            print(no1, "-", no2, "=", subtract(no1, no2))

        elif ch == '3':
            print(no1, "*", no2, "=", multiply(no1, no2))

        elif ch == '4':
            print(no1, "/", no2, "=", divide(no1, no2))

        # check if user wants another calculation
        # break the while loop if answer is no
        calc= input("Continue Calculation?(yes/no): ")
        if calc== "no":
            break

    else:
        print("Invalid Input")

Explanation:

  1. In this program, we have defined four functions addition, subtraction, multiplication, and division.
  2. We have provided the choices for add, subtract, multiply and divide. The user has to select from these 4 choices
  3. Calc is the variable that stores the value of whether the user wants to continue the calculation then he will type “yes”  else type “no” to break the loop.
  4. We are going to execute the program using the pycharm IDE. This IDE is the most widely used IDE created by JetBrains. Its community edition and professional edition are available in the market and it helps in the development of large development projects.
  5. Steps to run the program in pycharm IDE Right click on Project->New->Python File->”Filename.py”.
  6. Write the code->Click on ”Run” to execute the program

Output

The output of Calculator Program in Python using Pycharm IDE

Calculator Program using IDLE(Python)

IDLE (Integrated Development and Learning Environment) is a default editor that accompanies Python. This IDE can be used on Windows, Linux, and Mac OS. The IDLE is suitable for all beginners started learning python. Steps to run the above calculator program in Python using IDLE(Python) are:

  1. Open IDLE Shell 3.10.2
  2. Click on File->New File->Save->Save as Type “Python Files”
  3. Click on Run->Run Module

Output

The output of Calculator Program in Python using IDLE

Hence, after running on IDLE we will get the above output.

Calculator Program using Visual Studio Code

The visual studio code developed by Microsoft is a very lightweight and open-source IDE, mostly used in the development of python programs having good code debugging and editing features.

It provides all those strong features that most paid IDEs offer.

Steps to run the above calculator program in Python using Visual Studio Code.

  1. Install Visual Studio Code(Link on how to install visual studio code)
  2. Click on File->New Text File->Select a language of python to open the editor->Write the code
  3. Click on File->Save->Save as type->Python Files->Click on a Run command to see the execution
  4. The following output is visible once you click on the Run command on the Visual Studio Code.

Output

The output of Calculator Program with python using Visual Studio Code

Calculator program using Thonny

Thonny is an IDE for python that is designed for all python beginners. It provides various ways to step through the code and expression evaluation.

It is an ideal platform for learning python programming as provides a simple debugger, supports automatic syntax detection, and provides a detailed view of the variables used in python.

Steps to Run calculator program in python.

  1. Intall thonny(link for installing thonny).
  2. Click on File->New File->Type the code->Save the file as type python files with Filename.py.
  3. Install the package pip3 install thonny.
  4. Click the command Run, you will see the following output.

Output

The output of the Calculator Program using Python with Thonny

Calculator program using PyDev

PyDev is one of the most preferred open-source IDE by the Developers, It is flexible, and distributed as a third-party plugin for the Eclipse IDE. It is a strong python interpreter providing good support to python web development, debugging, and code analysis. It is also having the feature of auto code completion and Django integration.

Steps to Run the Calculator Program in Python on PyDev:

  1. Install Eclipse IDE and PyDev (Complete guide on how to install Eclipse IDE and PyDev)
  2. Click on File->New PyDev Project->Write the Project Name
  3. Click on File->Python Module->Select your Project Name as the Source Folder->Create a package->Create the Python file->Write the code.
  4. After clicking on Run Command you will get the following output for the calculator program.

Output

The output of Calculator Program using Python with PyDev IDE

Calculator Program using Jupyter

Jupyter is widely used for machine learning and Data Science. It is easy to use, supports code sharing, and numerical calculations, and allows code sharing and visualization.

It helps in combining the code, images, and text.

Jupyter notebook can easily be launched using anaconda distribution.

Steps to run the calculator program in Python using jupyter.

  1. Intall anaconda here ( complete guide to install Jupyter notebook)
  2. Open Anaconda Navigator ->Select Jupyter Launch ->
  3. Type the python code->Click on Run Command to see the following output.

Output

The output of the Calculator Program using Jupyter

Conclusion

There are a number of python IDEs available in the market having various features, you can choose which one to pick depending on the requirements. Here we have some of the python IDEs in which you can execute the calculator program using python. Hence different IDEs can be used in different environments.

Hope you find this article helpful. For more articles on python keep visiting our website.


Also Read:

Share:

Author: Ayush Purawr