Question: Need help finishing a Python 3 program that has a class for complex numbers! I'm creating a program that utilizes complex numbers and includes methods

Need help finishing a Python 3 program that has a class for complex numbers! I'm creating a program that utilizes complex numbers and includes methods for adding, subtracting, multiplying, dividing, and exponents for these complex numbers.

My program has two files: a file with the complex number class and another file which will be the main file. The main file contains two functions that will utilize the mathematical methods (the ones I stated above) from the complex class

The first function is called "a(c,k)" where "c" is the complex number and k is an integer: Need help finishing a Python 3 program that has a class for

The second function is called "b(c,k)": complex numbers! I'm creating a program that utilizes complex numbers and includes

I have created these functions but I'm a bit confused on how to use methods from the complex class for these two functions.

Here is my complex number class:

class Complex:

def __init__(self, x= 0, y= 0):

self.imag = imag

self.real = real

def __str__(self):

return str(self.real) + "+" + str(self.imag) + "i"

def getReal(self):

return self.real

def getImaginary(self):

return self.imag

def __add__(self, other):

x = self.real + other.real

y = self.imag + other.imag

return Complex(x, y)

def __sub__(self, other):

x = self.real - other.real

y = self.imag - other.imag

return Complex(x, y)

def __mul__(self, other):

x1 = self.real * other.real

x2 = self.imag * other.imag

x = x1 - x2

y1 = self.real * other.imag

y2 = self.imag * other.real

y = y1 - y2

return Complex(x, y)

def __truediv__(self, other):

x1 = self.real * other.real

x2 = self.imag * other.imag

denom = other.real ** 2 + other.imag **2

x = int((x1 + x2)/ denom)

y1 = self.real * other.imag * (-1)

y2 = self.imag * other.real

y = int((y1 + y2_) / denom)

return Complex(x, y)

def __pow__(self, other):

#need help

Here's the main file with the two functions:

from complex import complex

def a(c,k):

n = 0

for i in range(0, k):

expo += c ** n

return expo

def b(c,k):

function = ((1-c**(k+1))/(1-c)

return function

if __name__ == "__main__":

print(Welcome to Complex Numbers)

c = int(input('Enter Complex Number: '))

k = int(input('Enter Integer: '))

output = Complex(c, k)

func1 = a(output)

func2 = b(output)

print(func1)

print(func2)

I know my main file doesn't print the proper thing, but I don't know how to incorporate the two functions w/ the class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!