Checking the sides of a rectangle
Task
Write a function obsah_obdlznika(a, b) that returns the area of a rectangle. If either side is zero or negative, the function returns nothing and raises a ValueError with the message Strana musí byť kladná. (a side must be positive) instead.
The tests also call the function with bad sides and check both the type of the exception and its message.
Examples
Call
print(obsah_obdlznika(3, 4))
Expected output
12
Call
try: obsah_obdlznika(-1, 4) print("bez výnimky") except ValueError as e: print("ValueError:", e)Expected output
ValueError: Strana musí byť kladná.
After you submit, 4 hidden tests will also check your solution: a zero side, both sides negative, a decimal side, a tiny positive side.
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.