info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Breaking Math

Complete the function divide, which takes two parameters a and b and returns the division: a / b. There's one special case: if the parameter b is 0 you should raise a ValueError exception. You could implement it either using a try/except or just an if statement. If you have 2 minutes to spare, try both solutions!

Example:

divide(4, 2)  # 2
divide(8, 2)  # 4
divide(2, 0)  # ValueError Exception raised!

Test Cases

test division works - Run Test

def test_division_works():
    assert divide(10, 2) == 5

test division by zero - Run Test

import pytest

def test_division_by_zero():
    with pytest.raises(ValueError):
        divide(10, 0)
def divide(a, b): return a / b