def test_mult(self): result = calculator.mult(10, 10) self.assertEqual(result, 100) result = calculator.mult(2, 6) self.assertEqual(result, 12) result = calculator.mult(32, 12) self.assertEqual(result, 384)
def prob3(a,b): """Calculate and return the length of the hypotenuse of a right triangle. Do not use any methods other than those that are imported from the 'calculator' module. Parameters: a (float): the length one of the sides of the triangle. b (float): the length the other nonhypotenuse side of the triangle. Returns: The length of the triangle's hypotenuse. """ return calc.square_root(calc.add(calc.mult(a,a),calc.mult(b,b)))
def hypot(a, b): """Calculate and return the length of the hypotenuse of a right triangle. Do not use any functions other than those that are imported from your 'calculator' module. Parameters: a: the length one of the sides of the triangle. b: the length the other non-hypotenuse side of the triangle. Returns: The length of the triangle's hypotenuse. """ return calc.sqrt(calc.add(calc.mult(a, a), calc.mult(b, b))) raise NotImplementedError("Problem 3 Incomplete")
def main(): op = input("enter op.: +, -, *, /: ") num1 = int(input("enter a number: ")) num2 = float(input("enter a decimal number: ")) if op == "+": result = calculator.add(num1, num2) elif op == "-": result = calculator.sub(num1, num2) elif op == "*": result = calculator.mult(num1, num2) elif op == "/": result = calculator.div(num1, num2) else: print("Invalid operation") print(result)
def problem2_3(a,b): return c.sqrt(c.add(c.mult(a,a),c.mult(b,b)))
def test_multiplication(self): self.assertEqual(calc.mult(2, 3), 6)
import calculator a = int(input("Enter a value")) b = int(input("Enter b value")) print("addition is", calculator.sume(a, b)) print("substraction is", calculator.subs(6, 3)) print("muliplication is", calculator.mult(6, 3)) print("division is", calculator.divi(6, 3)) print("string is", calculator.string)
def test_mult3(self): result = calculator.mult(-2, -2) self.assertEqual(result, 4)
def test_mult(): assert mult(3.4, 2.1) == 7.14
def Mult(self, request, context): print("Request type and dump: ", type(request), '\n', request) response = calculator_pb2.MultAll() response.multValue = calculator.mult(request.value, request.factor) return response
def test_mult(self): assert mult(3, 12) == 36 assert mult(0, 300) == 0 assert mult(2.5, 3) == 7.5
def test_zero_x(self): x = 0 y = random.randint(1, 10) self.assertEqual(0, calculator.mult(x, y))
def test_random(self): x = random.randint(1, 10) y = random.randint(1, 10) self.assertEqual(x * y, calculator.mult(x, y))
from calculator import sume,subs,mult,divi x=int(input("Enter value for x: ")) y=int(input("Enter value for y: ")) print(sume(x,y)) print(subs(x,y)) print(mult(x,y)) print(divi(x,y))
def test_mult2(self): result = calculator.mult(2, 0) self.assertEqual(result, 0)
def test_mult1(self): result = calculator.mult(2, 2) self.assertEqual(result, 4)
def test_mult_error(): assert mult(3, 3) == 9
def test_mult_two_numbers(): assert mult(2, 2) == 4
def test_zero_y(self): x = random.randint(1, 10) y = 0 self.assertEqual(0, calculator.mult(x, y))
def hyp(a, b): return sqrt(add(mult(a, a), mult(b, b)))
import calculator if __name__ == '__main__': print(calculator.add(25, 56)) print(calculator.sub(86, 68)) print(calculator.mult(50, 60)) print(calculator.div(99, 25))
def test_mult(self): self.assertEqual(calculator.mult(2, 3), 6)
import calculator as c a = int(input("Enter the first number")) b = int(input("Enter the second number ")) ch = 0 while ch != 6: print("MENU") print( "1.ADD \n 2.SUBTRACT\n 3.MULTIPLICATON \n 4.DIVISION \n 5.MODULUS \n 6.EXIT" ) ch = int(input("enter your choice")) if (ch == 1): z = c.add(a, b) print(z) elif (ch == 2): z = c.sub(a, b) print(z) elif (ch == 3): z = c.mult(a, b) print(z) elif (ch == 4): z = c.div(a, b) print(z) elif (ch == 5): z = c.mod(a, b) print(z) elif (ch == 6): print("exit") else: print("Invalid Number")
import calculator as cal while True: num1 = int(input("Enter number : ")) num2 = int(input("Enter number : ")) ch = int(input("1 - add,2 - sub,3 - multi,4- div : ")) if ch == 1: result = cal.add(num1, num2) print(result) elif ch == 2: result = cal.sub(num1, num2) print(result) elif ch == 3: result = cal.mult(num1, num2) print(result) elif ch == 4: result = cal.div(num1, num2) print(result) else: break
from calculator import sume, subs, mult, divi, string print("addition is:", sume(6, 3)) print("subtraction is:", subs(6, 3)) print("multiplication is:", mult(6, 3)) print("division is:", divi(6, 3)) print("string is:", string)
def test_multiply(self): self.assertEqual(calculator.mult(3, 4), 12)
def testMultiplication(self): ''''Calculator should return the product of two numbers''' for num1, num2 in self.testValues: result = calculator.mult(num1, num2) self.assertEqual(18, result)
def test_mult2(self): result = calculator.mult(-2, 2) self.assertEqual(result, -4)