@@ -174,20 +174,25 @@ def __multiply(self):
174
174
175
175
# Overwrite __str__ for print(); Shows A, B and A*B
176
176
def __str__ (self ):
177
- A = "A = "
178
- B = "B = "
179
- C = "A*B = "
180
- for i in range (self .len_A ):
181
- A += str (self .polyA [i ]) + "*x^" + str (i ) + " + "
182
- for i in range (self .len_B ):
183
- B += str (self .polyB [i ]) + "*x^" + str (i ) + " + "
184
- for i in range (self .len_B + self .len_A - 1 ):
185
- C += (
186
- str (self .product [i ])
187
- + "*x^"
188
- + str (i )
189
- + " + "
190
- )
177
+ A = "A = " + " + " .join (
178
+ [
179
+ f"{ self .polyA [i ]} *x^{ i } "
180
+ for i in range (self .len_A )
181
+ ]
182
+ )
183
+ B = "B = " + " + " .join (
184
+ [
185
+ f"{ self .polyB [i ]} *x^{ i } "
186
+ for i in range (self .len_B )
187
+ ]
188
+ )
189
+ C = "A*B = " + " + " .join (
190
+ [
191
+ f"{ self .product [i ]} *x^{ i } "
192
+ for i in range (len (self .product ))
193
+ ]
194
+ )
195
+
191
196
return A + "\n \n " + B + "\n \n " + C
192
197
193
198
@@ -197,6 +202,6 @@ def __str__(self):
197
202
A = [0 , 1 , 0 , 2 ] # x+2x^3
198
203
B = (2 , 3 , 4 , 0 ) # 2+3x+4x^2
199
204
x = FFT (A , B )
200
- print (x .product ) # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5,
201
- # as [(-0+0j), (2+0j), (3+0j), (8+0j), (6+0j), (8+0j)]
202
- print (x )
205
+ print (x .product ) # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5,
206
+ # as [(-0+0j), (2+0j), (3+0j), (8+0j), (6+0j), (8+0j)]
207
+ print (x )
0 commit comments