[1] he also says that the iterator should not be int. “TypeError: ‘int’ object is not iterable”
It outputs
2
3
4
['4', '2', '3']
And it should display 4,3,2
P.S: the task itself that I want to test in python:
1) Any number X (put range)
2) flip it (ie 123 = 321) minus X
a = (x.reverse () - x)
3) b = a + a.reverse ()
As a result, the “focus” b should always = 1089
Answer 1, authority 100%
+ =
expects a whole collection on lists, not a single item. Use .append ()
to add just one element:
& gt; & gt; & gt; L = []
& gt; & gt; & gt; L + = 1
Traceback (most recent call last):
File "& lt; stdin & gt;", line 1, in & lt; module & gt;
TypeError: 'int' object is not iterable
& gt; & gt; & gt; L.append (1)
& gt; & gt; & gt; L
[1]
& gt; & gt; & gt; L + = [2, 3]
& gt; & gt; & gt; L
[1, 2, 3]
Answer 2
Done!
The youtube video helped.
x = 234; print x
inv_x = int (str (x) [:: - 1]); print inv_x
a = inv_x-x; print a
inv_a = int (str (a) [:: - 1]); print inv_a
b = a + inv_a; print b