LearnPy Hub
← Classes & Objects problems
Hard

Validated Property

Write a class Product with a price property whose setter raises ValueError for negative values. Read prices one per line until END; for each try setting it and print the stored price or invalid.

Input

Lines of numbers, then END.

Output

One line each.

Sample 1

Input
10
-5
2.5
END
Output
10.0
invalid
2.5

Sample 2

Input
0
END
Output
0.0
solution.py
Output appears here
Validated Property · Python practice problem · LearnPy Hub