A complex number is a number of the form \(a + bi\), whereby \(a\) and \(b\) are constants, and \(i\) is a special value that is defined as the square root of -1. Of course, you never try to actually calculate what the square root of -1 is, as that gives a runtime error; in complex numbers, you always let the \(i\) remain. For instance, the complex number \(3 + 2i\) cannot be simplified any further.

The sum of two complex numbers \(a + bi\) and \(c + di\) is defined as

\[(a + c) + (b + d)i\]

Assignment

We represent a complex number as a tuple of two numeric values. Write a function sum that calculates the sum of two complex numbers.11

Example

>>> sum((3, 4), (7, 2))
(13, 34)
  1. Actually, Python supports a separate data type complex that represents complex numbers, so there is not really a need to deal with complex numbers as tuples, but for the purpose of practicing with tuples this exercise works fine. 2