Reject Negative Arguments at the Door

Medium ⏱ 12 min 63% acceptance ★★★★☆ 4.4
Write positive_args(func) — a decorator raising ValueError if ANY positional argument is a negative number, before the wrapped function runs. Decorating deposit(account_id, amount) then centralizes validation that would otherwise repeat in every money function.

Examples

Example 1
Input
decorated_deposit(1, 500)
Output
normal result
Explanation

All positives pass through.

Example 2
Input
decorated_deposit(1, -500)
Output
ValueError
Explanation

The wrapper rejected before execution.

Constraints

  • Check only positional args that are int/float.
  • Raise before calling func.

Topics

Decoratorsvalidation

Companies

RazorpayPayPalHDFC Bank

Hints

Hint 1

isinstance(a, (int, float)) and a < 0.

Hint 2

any() over args.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.