Thursday, 24 February 2022

Program To make a simple calculator

# Program To make a simple calculator
while True:
    # take input from the user
    
    print("Select operation.")
    print("1.Add")
    print("2.Subtract")
    print("3.Multiply")
    print("4.Divide")
    option = input("Please Enter your option ")

    # check if option is valid
    if option in ('1', '2', '3', '4'):
        num1 = float(input("Enter first number: "))
        num2 = float(input("Enter second number: "))

        if option == '1':
            print(num1, "+", num2, "=", num1+num2)

        elif option == '2':
            print(num1, "-", num2, "=", num1-num2)

        elif option == '3':
            print(num1, "*", num2, "=", num1*num2)

        elif option == '4':
            print(num1, "/", num2, "=", num1/num2)
        
        # check if user wants to continue, if no
        # break the while loop
        continue_or_not = input("want to continue or not (yes or no) : ")
        if continue_or_not == "no":
          break
    
    else:
        print("The Input is invalid")
# full rights of this source code belongs to sai mohan pulamolu


Output



No comments:

Post a Comment