easy +10 pts

Timing Decorator

Measure and report function execution time with a reusable decorator.

Write a decorator `timed` that prints the execution time (in seconds, with 4 decimal places) of the decorated function when it is called. The printed line must be exactly: `Function <name> took <time> seconds` — where `<name>` is the function's `__name__` and `<time>` is the time in seconds formatted as a float with 4 decimal places (e.g., `0.1234`). The decorator should preserve the original function's metadata (name, docstring, etc.) using `functools.wraps`. Calling the decorated function should execute the original function and return its result without any modification. Define the decorator `timed` that can be applied with `@timed` syntax. **Important:** Do not import any third-party libraries. Use the standard library's `time` module. The decorator must work for functions with arbitrary arguments (positional and keyword).

Constraints

- The decorated function may accept any number of positional and keyword arguments. - The execution time is measured in seconds as a float. - The printed output format is exact; extra spaces or characters will be considered wrong. - Use `time.perf_counter()` for accurate timing. - The original function's result must be returned unchanged.

Example

```python
@timed
def add(a, b):
    """Return the sum."""
    return a + b

result = add(2, 3)
# prints: Function add took 0.0000 seconds (actual time will vary)
print(result)  # 5
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `functools.wraps` to preserve metadata.
Capture start time with `time.perf_counter()` before calling the function.
Print after the call, formatting with `:".4f"`.
Use `func.__name__` for the name.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.