<s>[INST] import random
import math
import os

flib = {'x': '0000', 'y': '0000'}

def add(a, b):
    return a + b

def sub(a, b):
    return a - b

def mul(a, b):
    return a * b

def div(a, b):
    return a / b if b != 0 else None

def mod(a, b):
    return a % b if b != 0 else None

def sqr(a):
    return a ** 2

def root(a):
    return math.sqrt(a) if a >= 0 else None

def formlib():
    print("Formula Library:")
    print("  +: addition")
    print("  -: subtraction")
    print("  *: multiplication")
    print("  /: division")
    print("  %: modulus")
    print("  ^: square")
    print("  r: square root")

def solve(a, b, f):
    if a is None or b is None:
        return "Invalid input"
    if f == '+':
        return add(a, b)
    if f == '-':
        return sub(a, b)
    if f == '*':
        return mul(a, b)
    if f == '/':
        return div(a, b)
    if f == '%':
        return mod(a, b)
    if f == '^':
        return sqr(a)
    if f == 'r':
        return root(a)
    return "Invalid operation"

def calc():
    while True:
        print(flib['x'])
        print(flib['y'])
        print("  Enter the value of x:")
        flib['x'] = input()
        try:
            flib['x'] = float(flib['x'])
        except ValueError:
            print("Invalid value")
            continue
        print("  Enter the value of y:")
        flib['y'] = input()
        try:
            flib['y'] = float(flib['y'])
        except ValueError:
            print("Invalid value")
            continue
        print("\nFormula Library:")
        print("  +: addition")
        print("  -: subtraction")
        print("  *: multiplication")
        print("  /: division")
        print("  %: modulus")
        print("  ^: square")
        print("  r: square root")
        print("\nEnter the operation:")
        op = input().lower()
        print(f"  Operation: {op}")
        if op in ['+', '-', '*', '/', '%']:
            print(f"  Result: {solve(flib['x'], flib['y'], op)}")
        elif op in ['^', 'r']:
            print("  Apply to x or y?[/INST]