Ejemplo n.º 1
0
def post_data():
    dat = int(request.get_data().decode("utf-8")[5:-1])
    print(dat)
    matrix1 = matrixgenerator(dat)
    matrix2 = matrixgenerator(dat)
    starttime = datetime.now()
    multiply(matrix1, matrix2)
    endtime = datetime.now()
    delta = str(endtime - starttime)
    print(delta)
    return (delta)
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
def evens_only_and_co(l, col):
    """Collects, evens, the multiplication of evens and addition of odds."""
    if is_null(l):
        return col(quote(), 1, 0)

    if is_atom(car(l)):
        if is_even(car(l)):
            return evens_only_and_co(
                cdr(l), lambda evens, p, s: col(cons(car(l), evens),
                                                multiply(car(l), p), s))

        return evens_only_and_co(
            cdr(l), lambda evens, p, s: col(evens, p, add(car(l), s)))

    return evens_only_and_co(
        car(l), lambda car_evens, carp, cars: evens_only_and_co(
            cdr(l), lambda cdr_evens, cdrp, cdrs: col(
                cons(car_evens, cdr_evens), multiply(carp, cdrp),
                add(cars, cdrs))))
Ejemplo n.º 4
0
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."
Ejemplo n.º 5
0
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}'
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def testCode(data):
    for number in data:
        if number == 0:
            print("Skipping 0\n")
            continue
        try:
            print("{0} squared is {1}\n".format(number,
                                                operations.squared(number)))
            print("{0} cubed is {1}\n".format(number,
                                              operations.cubed(number)))
            print("{0} multiplied by 3 is {1}\n".format(
                number, operations.multiply(number, 3)))
            print("{0} halved is {1}\n".format(number,
                                               operations.halved(number)))
            print("{0} quartered is {1}\n".format(
                number, operations.quartered(number)))
            print("{0} divided by zero is {1}\n".format(
                number, operations.divide(number, 0)))

        except ZeroDivisionError:
            print("Divisor cannot be zero\n")
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
# Create a new graph
Graph().as_default()

X = Placeholder()
c = Placeholder()

# Create a weight matrix for 2 outout classes:
# One with a weight vector (1, 1) for blue and one with a
# weight vector (-1, -1) for red
W = Variable([[1, -1], [1, -1]])

b = Variable([0, 0])
p = softmax(add(matmul(X, W), b))

# Cross-entropy loss
J = negative(reduce_sum(reduce_sum(multiply(c, log(p)), axis=1)))

# Create red points centered at (-2, -2)
red_points = np.random.randn(50, 2) - 2 * np.ones((50, 2))
# Create blue points centered at (2, 2)
blue_points = np.random.randn(50, 2) + 2 * np.ones((50, 2))

session = Session()
print(
    session.run(
        J, {
            X: np.concatenate((blue_points, red_points)),
            c: [[1, 0]] * len(blue_points) + [[0, 1]] * len(red_points)
        }))
 def test_multiplication(self):
     assert 100 == operations.multiply(10, 10)
Ejemplo n.º 11
0
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))
Ejemplo n.º 12
0
 def test_multiply(self):
     result = operations.multiply(10, 5)
     self.assertEqual(result, 50)
Ejemplo n.º 13
0
 def test_multiply(self):
     self.assertEqual(operations.multiply(10, 5), 50)
     self.assertEqual(operations.multiply(-1, 1), -1)
     self.assertEqual(operations.multiply(-1, -1), 1)
 def test_multiply_operation_returns_incorrect_value(self):
     self.assertEqual(multiply(10, 10), 100)
Ejemplo n.º 15
0
 def test2(self):
     self.assertEqual(operations.multiply(9, 2), 18)

def add(num1, num2):
    return num1 + num2


def multiply(num1, num2):
    return num1 * num2


def divide(num1, num2):
    return num1 / num2


add(2, 3)
multiply(5, 9)
divide(8, 4)


#any number of aguments:
def add_any_number_of_arguments(*nums):
    for num in nums:
        num += num
    return num


add_any_number_of_arguments(1, 23, 54, 54)
#Any number of Keyword/Named arguments:**kwargs
'''Similar to *args, we can use **kwargs to pass as many keyword
arguments as we want, as long as we use **.'''
Ejemplo n.º 17
0
import operations
from operations import square
from operations import *
from operations.packages_calculator.calculator.operations

print operations.multiply(3,2)

print square(3)

print power(2,3)

Ejemplo n.º 18
0
     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
     result = operations.divide(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
 else:
     print('Error.')