0 out of 464 challenges solved

Sum Series Calculation

Write a Python function `sum_series(n)` that calculates the sum of the series:

\[
S = n + (n-2) + (n-4) + \ldots
\]

The series continues until the term \( n - 2i \) becomes less than or equal to 0. For example:

- If \( n = 6 \), the series is \( 6 + 4 + 2 \), and the sum is \( 12 \).
- If \( n = 10 \), the series is \( 10 + 8 + 6 + 4 + 2 \), and the sum is \( 30 \).
- If \( n = 9 \), the series is \( 9 + 7 + 5 + 3 + 1 \), and the sum is \( 25 \).

#### Example Usage
```python [main.nopy]
print(sum_series(6))  # Output: 12
print(sum_series(10)) # Output: 30
print(sum_series(9))  # Output: 25
```

#### Constraints
- The input \( n \) will be a non-negative integer.
- If \( n \) is 0, the function should return 0.
def sum_series(n):
    """
    Calculate the sum of the series n + (n-2) + (n-4) + ... until the term is <= 0.

    Args:
    n (int): The starting number of the series.

    Returns:
    int: The sum of the series.
    """
    # Implement the function logic here
    pass