File tree 1 file changed +11
-13
lines changed
1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -175,25 +175,23 @@ def __multiply(self):
175
175
# Overwrite __str__ for print(); Shows A, B and A*B
176
176
def __str__ (self ):
177
177
A = "A = " + " + " .join (
178
- [
179
- f" { self . polyA [ i ] } *x^ { i } "
180
- for i in range ( self .len_A )
181
- ]
178
+ f" { coef } *x^ { i } "
179
+ for coef , i in enumerate (
180
+ self . polyA [: self .len_A ]
181
+ )
182
182
)
183
183
B = "B = " + " + " .join (
184
- [
185
- f" { self . polyB [ i ] } *x^ { i } "
186
- for i in range ( self .len_B )
187
- ]
184
+ f" { coef } *x^ { i } "
185
+ for coef , i in enumerate (
186
+ self . polyB [: self .len_B ]
187
+ )
188
188
)
189
189
C = "A*B = " + " + " .join (
190
- [
191
- f"{ self .product [i ]} *x^{ i } "
192
- for i in range (len (self .product ))
193
- ]
190
+ f"{ coef } *x^{ i } "
191
+ for coef , i in enumerate (self .product )
194
192
)
195
193
196
- return A + "\n \n " + B + " \n \n " + C
194
+ return "\n \n " . join (( A , B , C ))
197
195
198
196
199
197
# Unit tests
You can’t perform that action at this time.
0 commit comments