"""Create recovery_planner
Generated by Phi-Octopus Eden
2025-11-07 10:23:19.116077
"""

```python
from typing import Callable


class RecoveryPlanner:
    """
    A class to manage limited error recovery scenarios.

    Attributes:
        max_retries (int): The maximum number of times to retry on failure.
        fallback_function (Callable): The function to execute if all retries fail.

    Methods:
        plan_recovery: Attempts to execute a task with retries, falling back to the provided function if necessary.
    """

    def __init__(self, max_retries: int = 3, fallback_function: Callable = None):
        self.max_retries = max_retries
        self.fallback_function = fallback_function

    def plan_recovery(self, func: Callable, *args, **kwargs) -> any:
        """
        Attempt to execute a function with retries and fallback.

        Args:
            func (Callable): The function to be executed.
            *args: Arguments for the function.
            **kwargs: Keyword arguments for the function.

        Returns:
            The result of the successful execution or the fallback function's result if all retries fail.

        Raises:
            Exception: If max_retries are exhausted without success and no fallback is provided.
        """
        retries = 0
        while retries < self.max_retries:
            try:
                return func(*args, **kwargs)
            except Exception as e:
                print(f"Attempt {retries + 1} failed with error: {str(e)}")
                retries += 1

        if self.fallback_function is not None:
            result = self.fallback_function()
            print("Falling back to fallback function.")
            return result
        else:
            raise Exception(f"All {self.max_retries} attempts failed.")


# Example usage
def risky_operation():
    import random
    if random.randint(0, 1) == 0:  # Simulate a failure 50% of the time
        raise ValueError("Simulated error")
    return "Operation successful"


recovery_planner = RecoveryPlanner(max_retries=3)
result = recovery_planner.plan_recovery(risky_operation)
print(f"Result: {result}")
```