title: Syntax error in python code to find Prime-factors. Id appreciate if someone could help me
body: <p>I have been getting a syntax error with code which does prime-factorization</p>
  <p>The is this Code</p>
  <pre><code>from sys import argv
  from os import system, get_terminal_size
  from math import sqrt
  
  number = int(argv[1])
  width = get_terminal_size().columns
  prime_numbers = []
  prime_factors = []
  _ = system('clear')
  print() 
  
  def is_prime(n):
      for i in range(2, n):
          if n % i == 0:
              return False
  
      return True
  
  if is_prime(number):
      print(f&quot;It is a prime number \nIts only factors are 1 and itself \n1, {number}&quot;)
      exit()
  
  x = len(str(number))
  for i in range(2, int(sqrt(number))):
      if is_prime(i):
              prime_numbers.append(i)
  
              #print(f&quot;found &quot;)
  #print(prime_numbers)
  
  i = 0
  while True:
      if (number % prime_numbers[i] != 0):
          i += 1
          continue
      
      prime_factors.append(prime_numbers[i])
      print(&quot;%2d  | %3d&quot;.center(width) % (prime_numbers[i], number))
      print(&quot;_________&quot;.center(width))                                
      number /= prime_numbers[i]
      if number == 1:
          break
  print(&quot;1&quot;.center(width))
  
  print(&quot;Answer &quot;)
  
  i = len(prime_factors)
  j = 1
  
  for k in prime_factors:
      if j == i:
          print(k)
          break
  
      print(f&quot;{k}&quot;, end=&quot; X &quot;)
      j += 1
  </code></pre>
  <p>This works for small numbers , less than 4 or 5 digits but gives an index error for bigger ones.
  If I remove the sqrt function on line 24 it starts taking too long.</p>
  <p>The errors look like this</p>
  <pre><code>Traceback (most recent call last):
    File &quot;prime-factor.py&quot;, line 33, in &lt;module&gt;
      if (number % prime_numbers[i] != 0):
  IndexError: list index out of range
  
  real    0m0.049s
  user    0m0.030s
  sys 0m0.014s
  (base) Souravs-MacBook-Pro-5:Fun-Math-Algorithms aahaans$ time python3 prime-factor.py 145647
  </code></pre>
  <p>I am unable to resolve this issue, Id appreciate it if you could help me.</p>