title: List index out of range in loop with condition
body: <pre><code>n = input("How many average temperatures do you want to put in?" + "\n").strip()
  temperatures = []
  differences = []
  diff = 0
  
  print('')
  if int(n) &gt; 0 :
      for x in range (int(n)):
          temp = input("Input a average temperature: " + "\n").strip()
          temperatures.append(int(temp))
  
      for y in range(len(temperatures)):
          if y == len(temperatures):
              break
          diff = temperatures[y+1] - temperatures[y]
          differences.append(diff)
  
      print(differences)
  </code></pre>
  
  <p>Getting a list index out of range error on this line:</p>
  
  <pre><code>diff = temperatures[y+1] - temperatures[y]
  </code></pre>
  
  <p>This line basically finds the difference between 2 numbers in my list, so I am telling it to take the index of the number infront and subtract it from the number before. I figured out eventually when it gets to the last number, the [y+1] ends up being out of range, so at the start of the loop I put the condition that will break out of the loop when it gets to the last number in the list. </p>
  
  <p>But i'm still getting a index out of range error for some reason, and I don't understand why it's happening. Can anybody point out where i'm going wrong? </p>