Question
I have < NameError: name 'c1' is not defined> error --- python def __init__(self, a, b): self.a = a self.b = b def __add__(self, complex2):
I have < NameError: name 'c1' is not defined> error --- python
def __init__(self, a, b): self.a = a self.b = b def __add__(self, complex2): a_val = self.a + complex2.a b_val = self.b + complex2.b return Complex(a_val, b_val) def __sub__(self, complex2): a_val = self.a - complex2.a b_val = self.b - complex2.b return Complex(a_val, b_val) def __mul__(self, complex2): a_val = (self.a*complex2.a) - (self.b*complex2.b) b_val = (self.b*complex2.a) + (self.a*complex2.b) return Complex(a_val, b_val) def __truediv__(self, complex2): a_val = ((self.a*complex2.a) + (self.b*complex2.b)) / (complex2.a**2) + (complex2.b**2) b_val = (self.b*complex2.a) + (self.a*complex2.b) return Complex(a_val, b_val) def __eq__(self, complex2): #overloading equal operator if isinstance(complex2, Complex): return (self.a == complex2.a) and (self.b==complex2.b) else: return false def __lt__(self, complex2): #overloading less than operator return (self.a < complex2.a) and (self.b
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started