Esempio n. 1
0
def stdev():
    list2 = input()
    list2 = sorted(list2.split(","))
    N = len(list2)
    par = math_lib.sub(N, 1)
    num = 0
    for i in list2:
        num = math_lib.add(num, int(i))
    num2 = math_lib.div(num, N)
    res = 0
    for i in list2:
        tmp = math_lib.pow(math_lib.sub(int(i), num2))
        res = math_lib.add(res, tmp)
    s = math_lib.div(res, par)
    return math_lib.sqrt(s)
Esempio n. 2
0
    def test_sub(self):
        numbers_sub_1 = [
            24.567, -87.1, -38, -85, 1974, 348.5, 894, -67.1, 35, 5.5, 4, 10.4
        ]
        numbers_sub_2 = [
            -24.567, 87.1, 38, 85, -1974, -348.5, -894, 67.1, -35, -5.5, -4,
            -10.4
        ]

        for i in range(12):
            self.assertEqual(
                math_lib.sub(self.numbers_1[i], self.numbers_2[i]),
                numbers_sub_1[i])
            self.assertEqual(
                math_lib.sub(self.numbers_2[i], self.numbers_1[i]),
                numbers_sub_2[i])
Esempio n. 3
0
def calcBinary(a, b, operator):
    if operator == "+":
        return math.add(a, b)
    elif operator == "-":
        return math.sub(a, b)
    elif operator == "×":
        return math.mul(a, b)
    elif operator == "÷":
        try:
            return math.div(a, b)
        except Exception as e:
            return e
    elif operator == "√":
        try:
            return math.root(b, a)
        except Exception as e:
            return e
    elif operator == "^":
        try:
            return math.pow(a, b)
        except Exception as e:
            return e
    elif operator == "%":
        try:
            return math.mod(a, b)
        except Exception as e:
            return e
Esempio n. 4
0
    def test_func_cotan(self):
        self.assertEqual(math_lib.func_cotan(0), ValueError)
        self.assertEqual(math_lib.func_cotan(30), 1.732051)
        self.assertEqual(math_lib.func_cotan(45), 1)
        self.assertEqual(math_lib.func_cotan(90), 0)
        self.assertEqual(math_lib.func_cotan(180), ValueError)

        # TESTING NUMBER
        self.assertEqual(math_lib.func_cotan('a'), ValueError)
        self.assertEqual(math_lib.fact("test"), ValueError)
        self.assertEqual(math_lib.sub("test", "test"), ValueError)
Esempio n. 5
0
def low_priority_op(result, temp, i):
    """Calculating low priority operations

    Returns:
        int: Counter
    """
    if result[i] == '+':
        if result[i + 1] == '-':
            replace_binary(result, result[i + 1], i)
        elif (i - 1) < 0 and is_float(result[i + 1]):
            result.remove(result[i])
        elif is_float(result[i - 1]) and is_float(result[i + 1]):
            temp = math.add(float(result[i - 1]), float(result[i + 1]))
            replace_ternary(result, temp, i)
            i -= 1
        elif not is_float(result[i - 1]) or not is_float(result[i + 1]):
            set_err_msg(result, err_msg)
            return 0

    if result[i] == '-':
        if result[i + 1] == '+':
            replace_binary(result, result[i], i)
            if (i - 1) < 0:
                return 0
            else:
                return i
        elif (i - 1) < 0 and is_float(result[i + 1]):
            temp = -float(result[i + 1])
            replace_binary(result, temp, i)
        elif is_float(result[i - 1]) and is_float(result[i + 1]):
            temp = math.sub(float(result[i - 1]), float(result[i + 1]))
            replace_ternary(result, temp, i)
            i -= 1
        elif not is_float(result[i - 1]) or not is_float(result[i + 1]):
            set_err_msg(result, err_msg)
            return 0

    return (i + 1)
Esempio n. 6
0
import math_lib as ml

print('add 3 and 5')
print(ml.add(3,5))

print('subtract 12 from  34')
print(ml.sub(34,12))

print('multiply 2 and 90')
print(ml.mult(2,90))

print('divide 18 by 3')
print(ml.div(18,3))

print('divide 37 by 0')
print(ml.div(37,0))
Esempio n. 7
0
 def test_sub(self):
     self.assertEqual(math_lib.sub(10, 5), 5)
     self.assertEqual(math_lib.sub(-1, 1), -2)
     self.assertEqual(math_lib.sub(-1, -1), 0)
 def test_subtraction(self):
     #basic function
     self.assertEqual(math_lib.sub(456, 6), 450)
     self.assertEqual(math_lib.sub(754298, 754298), 0)
     self.assertEqual(math_lib.sub(4569823, 0), 4569823)
Esempio n. 9
0
    Richard Míček xmicek09

Date:
    16.4.2020
"""
import math_lib as math
import fileinput

num_array = ''
count = 0
average = 0
summ = 0

for line in fileinput.input():
    line.rstrip()
    num_array += line

num_array = num_array.split('\n')
num_array = [int(i) for i in num_array]

for num in num_array:
    average = math.add(average, num)
    count = math.add(count, 1)

average = math.div(average, count)

for num in num_array:
    summ = math.add(summ, math.exp(math.sub(num, average), 2))

deviation = math.ext(math.mul(math.div(1, (count - 1)), summ), 2)
print(deviation)