EasyPro challengePythonJavaScriptTypeScript
Exceptions — Safe Division
PythonExceptionsControl Flow
Implement solve(a, b) that:
- Returns
a / b(float division) ifb != 0. - Returns
Noneifb == 0(catch theZeroDivisionError). - Raises a
TypeErrorwith message"Inputs must be numbers"if either argument is not anintorfloat.
Examples
solve(10, 2)→5.0solve(7, 0)→Nonesolve("a", 2)→ raisesTypeError("Inputs must be numbers")
In JavaScript / TypeScript return null for a zero divisor and throw new TypeError('Inputs must be numbers'). Note that JavaScript never throws on division by zero — 7 / 0 is Infinity — so the zero case is a guard, not a catch.
Sample tests
Test #1Normal division
Input: [10,2]
Output: 5
Test #2Division by zero returns None
Input: [7,0]
Output: null
Test #3Float result
Input: [1,4]
Output: 0.25