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

Program in Python with proper indentation and syntax Design a class in Python th

ID: 3857855 • Letter: P

Question

Program in Python with proper indentation and syntax

Design a class in Python that represents complex numbers and supports important operations such as addition, subtraction, multiplication and division. For the Pyhton version you will need to implement the following functions for each operation:

op: Complex × Complex Complex

op: Complex × double Complex

op: double × Complex Complex

Where op is one of +, -, *, or /. In addition, you will need to overload the stream insertion operator << to print objects of this type.

A constructor must be defined as well as overloading the assignment operator to allow for implicit conversion from doubles to Complex. Any other methods you deem appropriate should also be included. The more complete your class the better.

The Python version you should also include functions for converting from complexes to strings.

The required files for this project are: a complex.h file that contains the declaration of the complex class, The python files required are a complex.py file.

Explanation / Answer

Answer for given python code:

Written the below python code for implemented as given conditions in the problem statements with addition, Sub, Mul and Div of complex numbers see the below code.

import math
i = math.sqrt(-1)

class Complex(object):

def __init__(Complex, a, b):
'''Create two Complex Numbers variables'''
a = 0
b = 0
return(Complex, a, b)


def __str__(Complex, a, b):
'''Return the complex number as a string to called funcion'''
a = 0
b = 0
return str(a, b)

def __add__(self):
'''This unction will add the two class complex numbers'''
i = math.sqrt(-1)
self.x = (a + bi) + (c + di) = (a + c) + (b + d)i

def __sub__(self):
'''This unction will sub the two class complex numbers'''
self.x = (a + bi) - (c + di) = (a - c) + (b - d)i

def __mul__(self):
'''This unction will multiply the two class complex numbers'''
self.x = (a + bi) * (c + di) = (ac - bd) + (bc + ad)i

def __div__(self):
'''This unction will divides the two class complex numbers'''
self.x = (a + bi) / (c + di) = (ac + bd)/(c**2 + d**2) + (bc - ad)i/(c**2 + d**2)

def __abs__(self):
'''Determines absolute value of complex numbers'''
self.x = math.sqrt(a**2 + b**2)