Calculator Program In Python

Calculator Program In Python

We are presenting you with one of the shortest and simplest calculator programs in python you could ever found. This calculator will contain the most basic functions you have seen in your life.

We will be creating a calculator that will add, subtract, divide, and multiply two numbers.

We will run the program until we don’t want to exit using a while loop, so that we can calculate as many as calculations we want.

If you want the calculator program in python gui then click here.

First, we will ask the user to choose one of the four basic operations i.e. “Addition“, “Subtraction“, “Multiplication“, and “Division“.

print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

We will also give choice to the user so that he can exit the program whenever he wants.

print("5. Exit")

Now, we will store the value entered by the user using the variable “choice“.

choice = int(input("Enter your choice: "))

Now, we will see the code and we will use comments to explain to you this basic Calculator Program In Python.


Calculator Program In Python: Code


# creating while loop
while True:
    # printing the available options
    print("1. Addition")
    print("2. Subtraction")
    print("3. Multiplication")
    print("4. Division")
    print("5. Exit")
    # asking user to Enter his choice
    choice = int(input("Enter your choice: "))
    # checking the choice between 1 and 4
    if (choice>=1 and choice<=4):
        # asking to enter two options
        print("Enter two numbers: ")
        # accepting first number
        num1 = int(input())
        # accepting second number
        num2 = int(input())
        # checking if number is 1
        if choice == 1:
            # adding
            res = num1 + num2
            # printing Addition
            print("Result = ", res)
        # checking if number is 2
        elif choice == 2:
            # Subtracting
            res = num1 - num2
            # printing Subtraction
            print("Result = ", res)
        # checking if number is 3
        elif choice == 3:
            # Multiplication
            res = num1 * num2
            # printing Result
            print("Result = ", res)
        # after checking all 3 choice,
        # only one operation left, i.e. for Division
        else:
            # Division
            res = num1 / num2
            # printing Result
            print("Result = ", res)
    # checking if the choice is 5
    elif choice == 5:
        # if choice is 5, we will exit the program
        exit()
    # everything, except the five choices is useless
    # so, we will print Wrong input..!!
    else:
        print("Wrong input..!!")

Calculator Program In Python: Output

1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 1
Enter two numbers: 
12
23
Result =  35
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 2
Enter two numbers: 
23
12
Result =  11
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 3
Enter two numbers: 
12
23
Result =  276
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 4
Enter two numbers:
24
12
Result =  2.0
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice: 5

This progam is very basic level Calculator Program In Python for beginners. But, we can add more choice and operations according to our needs.

Thanks for reading

Keep Learning

If you found something wrong in the article, then please let us know.


Also Read:


  • Aya Expanse supports multiple languages for diverse global applications
    Snapshot Aya Expanse is a cutting-edge multilingual model that has achieved exceptional performance across 23 different languages, setting a new benchmark for language understanding and generation capabilities. Why this matters The implications of Aya Expanse are significant, as it enables developers to create more inclusive and effective applications that can cater to diverse user bases…
  • Alibaba releases Page Agent on GitHub for public access
    Snapshot GitHub’s trending page has highlighted Page Agent, an open-source project by Alibaba. This innovative tool allows for efficient and simplified web page analysis, providing developers with valuable insights into page performance and structure. Why this matters Page Agent’s ability to analyze web pages and provide actionable data has significant implications for developers. By leveraging…
  • Google Sheets Gemini reaches new levels of performance and accuracy
    Gemini in Google Sheets has achieved state-of-the-art performance, with a 70.48% success rate in autonomously manipulating complex, real-world spreadsheets on the full SpreadsheetBench dataset. This milestone marks a significant advancement in AI-powered spreadsheet capabilities, positioning Gemini as a leader in the field. Situation The recent announcement of new beta features for Gemini in Sheets has…
  • Artificial intelligence boosts cardiac care in rural Australian communities
    Google is partnering with leading Australian health organizations to bring new AI tools to regional communities, with a $1 million investment from Google Australia’s Digital Future Initiative. This project aims to identify heart health risks early, making proactive care possible for more people, particularly in rural Australia where individuals are 60% more likely to die…
  • NVIDIA GTC 2026 Offers Insights into Future Artificial Intelligence Developments
    NVIDIA’s GTC 2026 conference is now underway, bringing together 30,000 attendees from 190 countries to explore the latest advancements in AI, with a focus on engineering implications. This year’s event introduces OpenClaw, the fastest-growing open source project in history, allowing attendees to build and deploy their own proactive, always-on AI assistants. What’s New with OpenClaw…


Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you

Related Articles