예제 #1
0
def product(ls, start, end):
	"""Multiplies 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 product of the numbers in the given range
	"""
	prod = ComplexNumber.create(1)
	for i in ls[start:end + 1]:
		prod = ComplexNumber.multiply(prod, i)
	return prod
예제 #2
0
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
예제 #3
0
def replace(ls, args, **kwargs):
    Validators.replace(ls, args)
    old = ComplexNumber.create(args[0])
    new = ComplexNumber.create(args[2])
    Commands.replace(ls, old, new, **kwargs)
예제 #4
0
def insert(ls, args, **kwargs):
    Validators.insert(ls, args)
    Commands.insert(ls, ComplexNumber.create(args[0]), int(args[2]), **kwargs)
예제 #5
0
def add(ls, args, **kwargs):
    Validators.add(args)
    Commands.add(ls, ComplexNumber.create(args[0]), **kwargs)
def create():
    assert (ComplexNumber.create("1+2j") == {"real": 1, "imag": 2})
    assert (ComplexNumber.create("3-2j") == {"real": 3, "imag": -2})
    assert (ComplexNumber.create("-1+12j") == {"real": -1, "imag": 12})