Home python TypeError: 'int' object is not iterable "if trying to add a number...

TypeError: ‘int’ object is not iterable “if trying to add a number to the list` end + = int (i) `

Author

Date

Category

[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

(c) thx https://www.youtube.com/watch?v=u1jdar3WADY

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions