← Back to challenges

Complex Numbers

PythonHardmathnumbersstringslogic

Instructions

Write a function that takes a string "a + bi" and returns a tuple (a, b).

Examples

complex_to_tuple("1 + 2i") ➞ (1, 2)

complex_to_tuple("6 + 9i") ➞ (6, 9)

complex_to_tuple("-7 - 2i") ➞ (-7, -2)

Notes

All strings are going to have the (±)a ± bi format, (where a and b are integers).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.