title: While loop or If code? Stuck with this function
body: <p>I'm asked to write a function <strong>generate_palindrome()</strong> that takes a given positive integer number <em>n</em> and applies the following procedure to it:</p>
  <p>(i) Check if the number is palindrome. If it is, then return it otherwise continue with the next step.</p>
  <p>(ii) Reverse the number and calculate the sum of the original number with the reversed number.</p>
  <p>(iii) Repeat from (i) (until a palindrome is found.)</p>
  <p>I wrote this function:</p>
  <pre><code>def generate_palindrome(n):
      numbers = list(str(n))
      for i in range(len(numbers)):
          if numbers[i] == numbers[-i-1]:
              return n
          else:
              while numbers[i] != numbers[-i-1]:
                  rev = list(reversed(numbers))
                  rev_num = int(''.join(rev))
                  n = n + rev_num
      return n
  </code></pre>
  <p>I don't know for what reason when I try a random number that is not already palindrome, the code doesn't respond, it's still running until an indefinite amount of time. I tried changing it with an <code>if</code> code but it doesn't iterate my function, so I think my only chance is with the <code>while</code> code, but maybe I'm the one who's wrong. What do you think?</p>