EasyPython

Exceptions — Safe Division

PythonExceptionsControl Flow

Implement solve(a, b) that:

  • Returns a / b (float division) if b != 0.
  • Returns None if b == 0 (catch the ZeroDivisionError).
  • Raises a TypeError with message "Inputs must be numbers" if either argument is not an int or float.

Examples

  • solve(10, 2)5.0
  • solve(7, 0)None
  • solve("a", 2) → raises TypeError("Inputs must be numbers")

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