# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

class Complex(object):
    def __init__(self, real, imag):
        self.real = real
        self.imag = imag

    def __add__(self, no):
        return Complex(self.real+no.real, self.imag+no.imag)

    def __sub__(self, no):
        return Complex(self.real-no.real, self.imag-no.imag)

    def __mul__(self, no):
        z1 = complex(self.real, self.imag)
        z2 = complex(no.real, no.imag)
        z = z1*z2
        return Complex(z.real, z.imag)

    def __truediv__(self, no):
        a = self.real
        b = self.imag
        c = no.real
        d = no.imag
        real_numerator = a*c + b*d
        imag_numerator = b*c - a*d
        denom = c*c + d*d
        real_div = real_numerator / denom
        imag_div = imag_numerator / denom
        return Complex(real_div, imag_div)

    def mod(self):
        return Complex((self.real**2+self.imag**2)**0.5, 0)

    def __str__(self) :
        return '{0:.2f}{1:+.2f}i'.format(self.real, self.imag)



StarcoderdataJupyterScriptsDedupFiltered