-3

Here is the condition : To take an integer and return true if it is symmetrical. A number is symmetrical if it's the same forwards and backwards.

The code:

def is_symmetrical(num):
number_list = list(num)
forwardList = []
backwardList = []
for num in number_list:
    forwardList.append(num)
    buffer = letter
    backwardList.append(num- num*2)
if forwardList == backwardList:
    return True
else :
    return False
Proteeti Prova
  • 1,079
  • 4
  • 25
  • 49
  • 5
    You get this error because, as the message says, an 'int' object is not iterable. `list('123')` will work, `list(123)` not. – Matthias Oct 12 '19 at 20:21
  • 1
    don't you mean list(str(num))? an integer sure isn't iterable... – B. Go Oct 12 '19 at 20:21
  • 3
    Also, you should include all the information you have about an error instead of expecting people to work it out themselves – Sayse Oct 12 '19 at 20:23
  • 3
    Possible duplicate of [How to check for palindrome using Python logic](https://stackoverflow.com/questions/17331290/how-to-check-for-palindrome-using-python-logic) – Sayse Oct 12 '19 at 20:24

2 Answers2

1

An int object isn’t iterable, so you have to convert the input to str format.

0

If you want to get the digits from the number in a list of ints, you could go for:

number_list = [int(num / (10 ** idx)) % 10 for idx in range(len(str(num))-1, -1, -1)]
matheburg
  • 2,097
  • 1
  • 19
  • 46