Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We have the class Complex and a function to multiply two complex numbers as foll

ID: 3854829 • Letter: W

Question

We have the class Complex and a function to multiply two complex numbers as follows. class Complex: def-init-(self, r, i ): self.real = r self.imag- i def multiply(c1, c2) c = Complex(0, 0) c.real = c1.reare2.real-c1.imag"c2.imag c.imag- c1.real*c2.imag + c1.imag c2.real return c We want the function power(c, n) to compute c to the power n, where the type of c is Complex, and n is a positive integer def power(c, n if n=1 : # Base case return blank1 else: n1= n // 2 cl- blank2 # Compute c to the power nl to store in c1 if n1=n2: c2-c1 else: c2- self._multiply(c1, c) return blank3 # return c to the power n To complete,--blank!--should be , blank2 shoulod be , and blank3 Fill-in the three blanks. -No space is allowed to enter due to automated grading. -The two functions do not belong to the class Complex. - Shortest possible expressions required.

Explanation / Answer

Q.1)
blank1 = c
Because when n = 1 it is equivalent to the number given. for example 2^1 = 2 where c is 2 and base is 1.

blank2 = c**n1
To store it in C1 we have to get c to the power of n1. thats why the answer is c**n1

blank2 = c2
In either case of the if condition in the function power, its the inner if condition which decides the value of c2 that to be returned. Thats why c2 is the answer.

2)
blank1 = []
We have to create empty list for positionList before appending element to it. thats why positionList = [], hence the answer.

blank2 = oprPos
As per function we have to add position of the operators found in given string s into positionList. Thats why oprPos is blank2.

blank3 = positionList[0]
Once the entire function is completed we have positionList filled with locations of the operators found from string s. Since we are interested in the leftmost operator which is the first location is positionList. Hence positionList[0].

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote