Ejemplo n.º 1
0
def operation(a, b):
    """mathematical operations with two data"""
    x = val_conv(a)
    y = val_conv(b)
    if x is None or y is None:
        return None
    if operator == '+':
        return f'Addition: {float(x) + float(y)}'
    if operator == '*':
        return f'multiplication: {float(x) * float(y)}'
    if operator == '/':
        return f'division: {float(x) / float(y)}'
    if operator == '-':
        return f'subtraction: {float(x) - float(y)}'
    if operator == '//':
        return f'division is complete: {float(x) // float(y)}'
    if operator == '%':
        return f'remainder of division of numbers: {float(x) % float(y)}'
    if operator == '**':
        return f'raise the number to the degree: {float(x) ** float(y)}'
    if operator == 'r':
        return f'round off the number: {round(float(x), int(y))}'
    if operator == 'b':
        return f'Decimal converted to binary: {bin(int(x))}'
    if operator == 's':
        return f'the sum of two numbers:  {int(x) + int(y)}'
    if operator == '^':
        return f'bitwise operation EXCLUSIVELY OR:  {int(x) ^ int(y)}'
Ejemplo n.º 2
0
def operation(a, b):
    """mathematical operations with two data"""
    x = val_conv(a)
    y = val_conv(b)
    if x is None or y is None:
        return None
    from perf1_operat import add, mult, div, sub, divb, divby, deg, addauto, bit, round
    oper = {
        '+': add(x, y),
        '*': mult(x, y),
        '/': div(x, y),
        '-': sub(x, y),
        '//': divb(x, y),
        '%': divby(x, y),
        '**': deg(x, y),
        'r': round(int(x), int(y)),
        's': addauto(x, y),
        '^': bit(x, y),
    }
    return oper[operator]
Ejemplo n.º 3
0
def operation1(a):
    """mathematical operations with two data"""
    x = val_conv(a)
    if x is None:
        return None
    from perf1_operat import sq1, bin
    oper1 = {
        'sq': sq1(x),
        'b': bin(int(x)),
    }
    return oper1[operator]
Ejemplo n.º 4
0
def one_x(a):
    """mathematical operations with one input"""
    x = val_conv(a)
    if operator == 'sq':
        if x is None:
            return None
        return f'The square root of the number is: {float(x) **(1/2)}'
    if operator == 'sqrt':
        from math import sqrt
        if x is None:
            return None
        return f'square root: {sqrt(x)}'