def main(): print("Select Operation") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") print("5.Power") choice = input("Enter Choice(+,-,*,/,^): ") num1 = int(input("Enter first number: ")) num2 = int(input("Enter Second number:")) if choice == '+': print(num1, "+", num2, "=", add(num1, num2)) elif choice == '-': print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '*': print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '/': print(num1, "/", num2, "=", divide(num1, num2)) elif choice == '^': print(num1, "^", num2, "=", power(num1, num2)) else: print("Invalid input") main()
def ifthen_operate(number_1, number_2): operation = request.args.get('operation') if operation == "addition": return "{}".format(add(number_1, number_2)) elif operation == "subtraction": return "{]".format(subtract(number_1, number_2)) elif operation == "multiplication": return "{}".format(multiply(number_1, number_2)) elif operation == "division": return "{}".format(divide(number_1, number_2)) else: return "Error: need an operation for two numbers. After the url, type 'operation=', then the operation. Operations are: addition, subtraction, multiplication, and division."
def calculate_expression(expression): (x, sign, y) = expression.split(' ') x = float(x) y = int(y) if sign == '+': result = add(x, y) elif sign == '-': result = subtract(x, y) elif sign == '*': result = multiply(x, y) elif sign == '/': result = divide(x, y) elif sign == '^': result = power(x, y) else: raise Exception(f'Invalid sign {sign}') return f'{result:.2f}'
def run(): print("This program will help with simple calculations. What do you want to do?") print("1 - add numbers") print("2 - subtract numbers") print("3 - multiply numbers") print("4 - divide numbers") answer = input(">> ") a = int(input("A=")) b = int(input("B=")) if answer == "1": result = add(a, b) if answer == "2": result = subtract(a, b) if answer == "3": result = multiply(a, b) if answer == "4": result = divide(a, b) print("Result =", result)
def operate(choice): if choice == 1: number_1 = input("\nEnter First number") number_2 = input("\Enter second number") result = "Sum of " + number_1 + 'and' + number_2 + 'is:' + str( operations.add(int(float(number_1)), int(float(number_2)))) return result if choice == 2: number_1 = input("\nEnter First number") number_2 = input("\Enter second number") result = "Sum of" + number_1 + 'and' + number_2 + 'is:' + str( operations.subtract(int(float(number_1)), int(float(number_2)))) return result if choice == 3: number_1 = input("\nEnter First number") number_2 = input("\Enter second number") result = "Sum of" + number_1 + 'and' + number_2 + 'is:' + str( operations.multiplication(int(float(number_1)), int( float(number_2))))
def operate(choice): if choice == 1: number_1 = input("\nEnter first number") number_2 = input("\nEnter second number\n") result = 'Sum of ' + number_1 + ' and ' + number_2 + ' is :' + str( operations.add(int(float(number_1)), int(float(number_2)))) elif choice == 2: number_1 = input("\nEnter first number") number_2 = input("\nEnter second number\n") result = 'Difference of ' + number_1 + ' and ' + number_2 + ' is :' + str( operations.subtract(int(float(number_1)), int(float(number_2)))) elif choice == 3: number_1 = input("\nEnter first number") number_2 = input("\nEnter second number\n") result = 'Difference of ' + number_1 + ' and ' + number_2 + ' is :' + str( operations.multiply(int(float(number_1)), int(float(number_2)))) else: number_1 = input("\nEnter the number") # number_2=input("\nEnter second number\n") result = 'Log of ' + number_1 + ' is :' + str( scientific.log(int(float(number_1)))) return result
def test_subtraction(self): assert 2 == operations.subtract(4, 2)
import operations print("Welcome to our special calculator where no result is under 0") print("Choose an operation:") print("a) Add") print("b) Subtract") print("c) Multiply") print("d) Divide") user_choice = input("> ") # a, b, c, or d number1 = int(input("Please give me a number: ")) number2 = int(input("Please give me another number: ")) if user_choice == 'a': print(operations.add(number1, number2)) if user_choice == 'b': print(operations.subtract(number1, number2)) if user_choice == 'c': print(operations.multiply(number1, number2)) if user_choice == 'd': print(operations.divide(number1, number2))
def test_subtract(self): self.assertEqual(operations.subtract(10, 5), 5) self.assertEqual(operations.subtract(-1, 1), -2) self.assertEqual(operations.subtract(-1, -1), 0)
import operations try: a=float(input("enter a")) b=float(input("enter b")) print(operations.add(a,b)) print(operations.subtract(a,b)) print(operations.multi(a,b)) print(operations.divide(a,b)) except: print("it is string")
def calc_side(side, hypotenuse): """ Calculates a side through theorem """ return square_root(subtract(power(hypotenuse, 2), power(side, 2)))
def test_substract_operation_returns_correct_value(self): self.assertEqual(subtract(100, 90), 10)
# print('operands_working: {}'.format(operands_working)) # print('operands: {}'.format(operands)) # print('operators_working: {}'.format(operators_working)) for x in operators_working: if x == '+': # Addition result = operations.add(operands[0], operands[1]) operands.pop(0) # remove operand 1 operands.pop(0) # remove operand 2 operands.insert( 0, result ) # places the result of operation at the place of two used operands elif x == '-': # Subtraction result = operations.subtract(operands[0], operands[1]) operands.pop(0) # remove operand 1 operands.pop(0) # remove operand 2 operands.insert( 0, result ) # places the result of operation at the place of two used operands elif x == '*': # Subtraction result = operations.multiply(operands[0], operands[1]) operands.pop(0) # remove operand 1 operands.pop(0) # remove operand 2 operands.insert( 0, result ) # places the result of operation at the place of two used operands elif x == '/': # Subtraction