def generate_code():
    """
    Generate a Python function that calculates the sum of two numbers,
    test if it runs, score by success/failure, and return working code.

    Returns:
        str: A string representing the generated code.
    """

    import random
    num1 = random.randint(0, 10)
    num2 = random.randint(0, 10)

    code = f"def add({num1}, {num2}):\n"
    code += "    return {num1} + {num2}\n"
    code += "print(add(" + str(num1) + ", " + str(num2) + "))"

    try:
        exec(code)
        return code
    except Exception as e:
        return f"Error: {str(e)}"