Exemplo n.º 1
0
def multiinsertLR_starred_and_co(new, oldL, oldR, l, col):
    """Inserts new to the left of `oldL` and to the right of `oldR`.

    NB: Uses a collector func to gather new list and count L, R inserts
    """
    if is_null(l):
        return col(quote(), 0, 0)

    if is_atom(car(l)):
        if is_eq(car(l), oldL):
            return multiinsertLR_starred_and_co(
                new, oldL, oldR, cdr(l), lambda newl, L, R: col(
                    cons(new, cons(oldL, newl)), add1(L), R))

        if is_eq(car(l), oldR):
            return multiinsertLR_starred_and_co(
                new, oldL, oldR, cdr(l), lambda newl, L, R: col(
                    cons(oldR, cons(new, newl)), L, add1(R)))

        return multiinsertLR_starred_and_co(
            new, oldL, oldR, cdr(l),
            lambda newl, L, R: col(cons(car(l), newl), L, R))

    return multiinsertLR_starred_and_co(
        new, oldL, oldR, car(l),
        lambda carnl, carL, carR: multiinsertLR_starred_and_co(
            new, oldL, oldR, cdr(l), lambda cdrnl, cdrL, cdrR: col(
                cons(carnl, cdrnl), add(carL, cdrL), add(carR, cdrR))))
Exemplo n.º 2
0
def add_pokemon_name(pokemon):
    try:
        operations.add(pokemon)
    except:
        raise Exception("Could not add pokemon to team")

    browse_text_variable.set(f"{pokemon.title()} has been added to your team")
Exemplo n.º 3
0
def check_validity_action(x):
    if re.match(r"^a\s+(\"(([\w]+)\s?)+\")\s+(((\(-?\d+,-?\d+\))\s?)\s?)+$",
                x):
        operations.add(x)
    elif re.match(r"^c\s+(\"(([\w]+)\s?)+\")\s+(((\(-?\d+,-?\d+\))\s?)\s?)+$",
                  x):
        operations.change(x)
    elif re.match(r"^r\s+(\"(([\w]+)\s?)+\")\s?$", x):
        operations.remove(x)
    elif re.match(r"^g\s?$", x):
        operations.generateGraph()
    elif re.match(r"\n", x):
        print('Error: Please input data.')
    else:
        print('Error: Input format unrecognised.')
Exemplo n.º 4
0
def run_add():
    """adds a and b"""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    res = add(a, b)

    return str(res)
Exemplo n.º 5
0
def addition():
    '''Add a and b together'''
    a = int(request.args.get('a'))
    b = int(request.args.get('b'))
    result = add(a, b)

    return str(result)
Exemplo n.º 6
0
def addition():
    """Adds a and b parameters"""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 7
0
def add_nums():
    """return the sum of a and b parameters"""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 8
0
Arquivo: app.py Projeto: ben-hong/calc
def add():
    a = request.args["a"]
    b = request.args["b"]

    add = operations.add(int(a), int(b))

    return str(add)
Exemplo n.º 9
0
def add_params():
    a = int(request.args.get('a'))
    b = int(request.args.get('b'))
    
    result = add(a, b)

    return str(result)
Exemplo n.º 10
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()
Exemplo n.º 11
0
def add_request():
    """Handle GET request to add two numbers"""
    a = int(request.args["a"])
    b = int(request.args["b"])
    result = add(a, b)

    return str(result)
Exemplo n.º 12
0
def add():
    a = int(request.args.get('a'))
    b = int(request.args.get('b'))

    res = operations.add(a, b)

    return str(res)
Exemplo n.º 13
0
def add_num():
    """Add a and b"""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 14
0
def addition():
    """this function adds a and b, 
    and if a parameter is missing, the parameter is defaulted to 0"""
    a = int(request.args.get("a", 0))
    b = int(request.args.get("b", 0))
    result = add(a, b)
    return f"<h1>adding: {result}</h1>"
Exemplo n.º 15
0
def run_add():
    '''add a and b'''
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
def do_add():
    """adds a to be"""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 17
0
def add_nums():
    """returns sum of a and b"""

    a = int(request.args.get("a"))
    b = int(request.args.get("b"))

    return (str(add(a, b)))
Exemplo n.º 18
0
def do_add():
    """Add a and b parameters."""

    a = int(request.args.get('a'))
    b = int(request.args.get('b'))
    result = add(a, b)

    return str(result)
Exemplo n.º 19
0
def add_num():
    '''
    Add a and b
    '''
    a = int(request.args.get('a'))
    b = int(request.args.get('b'))
    result = add(a, b)
    return f"<h1>{a} + {b} is {result}</h1>"
Exemplo n.º 20
0
def add_input():
    """Add a and b parameters"""
    # Convert string to numbers
    a = int(request.args["a"])
    b = int(request.args["b"])
    result = add(a, b)

    return f"<h1>{result}</h1>"
Exemplo n.º 21
0
def to_add():
    """add a and b params"""

    a = int(request.args["a"])
    b = int(request.args["b"])
    result_add = add(a, b)
    # DO WE ALWAYS HAVE TO STRING THE RESULTS???
    return str(result_add)
Exemplo n.º 22
0
def _add(a, b):
    """Calls add() function from operations and returns the result."""
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))

    addition = add(a, b)
    html = f"<html><body><h1>{a} + {b} is...</h1><h3>{addition}</h3></body></html"
    return html
Exemplo n.º 23
0
    def _value(nexp):
        if is_eq(op(nexp), _quote("+")):
            return add(_value(fse(nexp)), (_value(sse(nexp))))

        if is_eq(op(nexp), _quote("x")):
            return multiply(_value(fse(nexp)), (_value(sse(nexp))))

        return expon(_value(fse(nexp)), (_value(sse(nexp))))
Exemplo n.º 24
0
def add_a_and_b():
    """handles add functionality"""
    try:
        a = int(request.args['a'])
        b = int(request.args['b'])
        return str(operations.add(a, b))
    except Exception as e:
        return f"{e}"
Exemplo n.º 25
0
def search_add():
    """ handles GET requests with query parameters a and b and then adds the two numbers together"""

    a = int(request.args["a"])
    b = int(request.args["b"])
    sum = add(a, b)

    return str(sum)
Exemplo n.º 26
0
def get_add():
    """
    Add a and b and returns result as the body.
    """
    a = float(request.args["a"])
    b = float(request.args["b"])

    return str(operations.add(a, b))
Exemplo n.º 27
0
def math_add():
    """Add a and b parameters."""

    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 28
0
def do_add():
    """ add a and b params"""

    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a,b)

    return str(result)
Exemplo n.º 29
0
def add():
    '''It take 2 parameter and adds them
    >>> 4 + 5 = 9
    '''
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    result = add(a, b)

    return str(result)
Exemplo n.º 30
0
def sum_query_string_options():
    """Handle GET: Add a and b and return result in body."""

    a = int(request.args["a"])
    b = int(request.args["b"])

    result = op.add(a, b)

    return f"<h1>The sum of a and b is {result}!</h1>"
Exemplo n.º 31
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."
Exemplo n.º 32
0
Arquivo: main.py Projeto: ikajic/teach
import operations as op

x, y = 5, 10
print 'Using arguments:', x, y
print 'Sum:', op.add(x, y)
print 'Difference:', op.sub(arg1=x, arg2=y)
print 'Difference again:', op.sub(arg2=x, arg1=y)

x, y = 10.0, 0
print 'Using arguments:', x, y
print 'Multiplication:', op.mul(x, x)
print 'Division:', op.div(y, x)
print 'Division:', op.div(x, y)