Simple Calculator using Python
Posted by Samath
Last Updated: January 09, 2017

This is a simple calculator using the python programming language. The program provide a menu to the user to choose the type of operation they want to perform, after which the program will ask for 2 number to calculate. The program will run infinitely until the user quit the program. 

isRunning = True 

while isRunning:
    print("\n1 = Addition")
    print("2 = Subtraction")
    print("3 = Multiplication")
    print("4 = Division")
    print("5 = Exit program")
    cmd = int(input("Enter number : "))
    if cmd == 1:
        print("Addition")
        first = int(input("Enter first number :"))
        second = int(input("Enter second number :"))
        result = first + second
        print(str(first) +'+' +str(second) +'=' + str(result))
    elif cmd == 2:
        print("Subtraction")
        first = int(input("Enter first number :"))
        second = int(input("Enter second number :"))
        result = first - second
        print(str(first) +"-" +str(second) +"=" + str(result))
    elif cmd == 3:
        print("Multiplication")
        first = int(input("Enter first number :"))
        second = int(input("Enter second number :"))
        result = first * second
        print(str(first) + "*" +str(second) +"=" + str(result))
    elif cmd == 4:
        print("Division")
        first = int(input("Enter first number :"))
        second = int(input("Enter second number :"))
        result = first / second
        print(str(first) +"/" +str(second) +"=" + str(result))
    elif cmd == 5:
        print("Quit!")
        isRunning = False

 

Related Content
Simple Calculator using C#
Simple Calculator using C#
Samath | Dec 30, 2020
Calculator Program in Java
Calculator Program in Java
Samath | Jan 07, 2021
Simple C++ Calculator
Simple C++ Calculator
Samath | Jan 05, 2017
GPA Calculator using C#
GPA Calculator using C#
Samath | Jan 01, 2021
Simple GPA calculator in Java
Simple GPA calculator in Java
Samath | Jan 17, 2024
GPA Calculator in C++
GPA Calculator in C++
Samath | Jan 17, 2024
GPA Calculator using Python
GPA Calculator using Python
Samath | Jan 20, 2024
Scientific Calculator using C#
Scientific Calculator using C#
Samath | Jan 08, 2021