Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 complex2.a) and (self.b>complex2.b) def __ge__(self, complex2):#overloading greater than or equal operator return (self.a >= complex2.a) and (self.b>=complex2.b) def __abs__(self): return (self.a**2+self.a**2)**0.5 def __str__(self): return str(self.a)+"+i"+str(self.b) def main(): input_line = input("Enter the first complex number: ") input_line = list(map(float,input_line.split())) a, b = input_line[0], input_line[1] c1 =Complex(a, b) input_line = input("Enter the second complex number: ") input_line = list(map(float,input_line.split())) a, b = input_line[0], input_line[1] c2 = Complex(a, b) print() print("c1 is", c1) print("c2 is", c2) print("|" + str(c1) + "| = " + str(abs(c1))) print("|" + str(c2) + "| = " + str(abs(c2))) print(c1, " + ", c2, " = ", c1 + c2) print(c1, " - ", c2, " = ", c1 - c2) print(c1, " * ", c2, " = ", c1 * c2) print(c1, " / ", c2, " = ", c1 / c2) print("Is c1 < c2?", c1 < c2) print("Is c1 <= c2?", c1 <= c2) print("Is c1 > c2?", c1 > c2) print("Is c1 >= c2?", c1 >= c2) print("Is c1 == c2?", c1 == c2) print("Is c1 != c2?", c1 != c2) print("Is c1 == 'Hello There'?", c1 == 'Hello There') print("Is c1 != 'Hello There'?", c1 != 'Hello There') main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago