title: Missing Term Arithmetic Progression - Clean up my code
body: <p>I just tried a little online programming quiz that asked me to solve this problem as quickly as possible. I got the right answer but I know it isn't pretty. I'm trying to become a better programmer and write cleaner, more efficient code so please give me some tips. I've included the description below. PS I think this algorithm fails for the case N=3</p>
  
  <pre><code># Enter your code here. Read input from STDIN. Print output to STDOUT
  import sys
  N= int(sys.stdin.readline())
  stringdata =  sys.stdin.readline()
  array = stringdata.split(' ')
  diff1=[0]*(N-1)
  diff2 = [0]*(N-2)
  index = 0
  diff = 0
  for i in  range(0,len(array)-1):
      first_diff[i] = int(array[i+1])-int(array[i])
  for i in   range(0,len(diff1)-1):
      second_diff[i] = first_diff[i+1]-first_diff[i]
      if second_diff[i] == 0:
          diff = first_diff[i]
      else:
          index = i
  print(int(array[index])+diff)
  </code></pre>
  
  <p>Task: Find the missing term in an Arithmetic Progression.</p>
  
  <p>An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: Exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP.  Find the missing term.   </p>
  
  <p>Input Format
  The first line contains an Integer N, which is the number of terms which will be provided as input.
  This is followed by N consecutive Integers, with a space between each pair of integers. All of these are on one line, and they are in AP (other than the point where an integer is missing).</p>
  
  <p>Output Format
  One Number which is the missing integer from the series.</p>
  
  <p>Sample Input
  5
  1 3 5 9 11  </p>
  
  <p>Sample Output
  7</p>