• Simple Calculator Program In Python

    Here we will build a simple calculator using python.The operations in calculator are:

    • addition of 2 numbers
    • subtraction of 2 numbers
    • multiplication of 2 numbers
    • division of 2 numbers
    • Remainder of 2 numbers

    Below is the code:

    print("select operation")
    print("1.Add")
    print("2.subtract")
    print("3.multiply")
    print("4.Division")
    print("5.Reminder")

    def add(x,y):
        return x+y
    def subtract(x,y):
        return x-y
    def multiply(x,y):
        return x*y
    def divide(x,y):
        return x/y
    def remainder(x,y):
        return x%y
    choice = input("input ur choice(1/2/3/4/5):")
    num1=int(input('enter 1st no:'))
    num2=int(input('enter 2nd no:'))

    if choice == '1' :
        print(num1,"+",num2,"=",add(num1,num2))
    elif choice == '2' :
        print(num1,"-",num2,"=",subtract(num1,num2))
    elif choice == '3'  :
        print(num1, "-", num2, "=", multiply(num1, num2))
    elif choice == '4':
        print(num1, "-", num2, "=", divide(num1, num2))
    elif choice == '5':
        print(num1, "%", num2, "=", remainder(num1, num2))
    else:
        print("Invalid input entered")


    Output:
    select operation
    1.Add
    2.subtract
    3.multiply
    4.Division
    5.Reminder
    input ur choice(1/2/3/4/5):5
    enter 1st no:80
    enter 2nd no:20

    80 % 20 = 0
    ----------------
    select operation
    1.Add
    2.subtract
    3.multiply
    4.Division
    5.Reminder
    input ur choice(1/2/3/4/5):1
    enter 1st no:80
    enter 2nd no:20

    80 + 20 = 100


  • You might also like

    No comments:

    Post a Comment