Created
December 10, 2020 23:20
-
-
Save MLWhiz/1790e82e2ddc875fb0b57a086383898a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Complex: | |
def __init__(self, re=0, im=0): | |
self.re = re | |
self.im = im | |
def __add__(self, other): | |
# If Int or Float Added, return a Complex number where float/int is added to the real part | |
if isinstance(other, int) or isinstance(other, float): | |
return Complex(self.re + other,self.im) | |
# If Complex Number added return a new complex number having a real and complex part | |
elif isinstance(other, Complex): | |
return Complex(self.re + other.re , self.im + other.im) | |
else: | |
raise TypeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment