Medium
Python Code Optimization
Optimize a Python function for better readability and performance.
📝 Prompt Content
Review the following Python code snippet that calculates the factorial of a number using recursion. Rewrite it to use an iterative approach instead to avoid recursion depth errors. Add docstrings and type hints. Ensure the code handles edge cases such as negative input or non-integer types gracefully by raising appropriate exceptions.