def sums(ls, start, end): """Sums up all the numbers in the given range of the list Input data: ls -- The list start -- The starting point of the range end -- The end point of the range Output data: The sum of the numbers in the given range """ s = ComplexNumber.create(0) for cn in ls[start:end + 1]: s = ComplexNumber.add(s, cn) return s
def sum(): assert (ComplexNumber.add(cn(1), cn(2j)) == cn(1 + 2j)) assert (ComplexNumber.add(cn(-1), cn(2j)) == cn(-1 + 2j)) assert (ComplexNumber.add(cn(2j), cn(2j)) == cn(4j))