title: I want to improve speed of my algorithm with multiple rows input. Python. Find average of consequitive elements in list
body: <p>I need to find average of consecutive elements from list.
  At first I am given lenght of list,</p>
  
  <p>then list with numbers,</p>
  
  <p>then am given how many test i need to perform(several rows with inputs),</p>
  
  <p>then I am given several inputs to perform tests(and need to print as many rows with results)</p>
  
  <p>every row for test consist of start and end element in list.</p>
  
  <pre><code>My algorithm:
  nu = int(input())              # At first I am given lenght of list
  numbers = input().split()      # then list with numbers
  num = input()                  # number of rows with inputs
  k =[float(i) for i in numbers] # given that numbers in list are of float type
  i= 0
  while i &lt; int(num):
   a,b = input().split()          # start and end element in list
   i += 1
   print(round(sum(k[int(a):(int(b)+1)])/(-int(a)+int(b)+1),6)) # round up to 6 decimals
  </code></pre>
  
  <p>But it's not fast enough.I was told it;s better to get rid of "while" but I don't know how. Appreciate any help.</p>
  
  <pre><code>Example:
  Input:
  8 - len(list)
  79.02 36.68 79.83 76.00 95.48 48.84 49.95 91.91 - list
  10 - number of test
  0 0 - a1,b1
  0 1
  0 2
  0 3
  0 4
  0 5
  0 6
  0 7
  1 7
  2 7
  Output:
  79.020000
  57.850000
  65.176667
  67.882500
  73.402000
  69.308333
  66.542857
  69.713750
  68.384286
  73.668333
  </code></pre>