Learning Scientific Programming with Python (2nd edition)

P4.1.2: String representation of a vector

Question P4.1.2

Adapt the function of Example E4.3, which returns a vector in the following form:

>>> print(str_vector([-2, 3.5]))
-2i + 3.5j
>>> print(str_vector((4, 0.5, -2)))
4i + 0.5j - 2k

to raise an exception if any element in the vector array does not represent a real number.