LearnPy Hub
← Decorators problems
Hard

Convert Arguments From Annotations

Write a decorator coerce that reads func.__annotations__ and converts each positional argument to its annotated type before calling (arguments without an annotation are left alone). Decorate def order(item: str, qty: int, price: float, note) that returns a summary line. Read lines of four words until END and print order(*words), or bad input if a conversion fails.

Input

Lines, then END.

Output

Lines.

Sample 1

Input
tea 3 20 hot
cake x 80 sweet
END
Output
3 x tea = 60.00 (hot)
bad input

Sample 2

Input
pen 10 12.5 blue
END
Output
10 x pen = 125.00 (blue)
solution.py
Output appears here
Convert Arguments From Annotations · Python practice problem · LearnPy Hub