Given a list:

a = [220.50,224.68,219.66,224.00, 225.20,231.00,225.00,228.38, 228.90,229.41,223.51,224.47, 231.07,231.07,215.00,216.00, 218.00,224.23,215.71,219.02, 219.50,223.99,215.00,223.99, 223.90,224.50,220.00,221.50, 218.75,221.30,217.01,221.01] 

It is necessary to go through it with a cycle; cut the first five objects, add them together, divide by 5 and save in a variable. Then compare this result with the sixth object a[5] and, if the sixth object a[5] greater than the previous result, assign he is 2 , otherwise he will be assigned 1 And so it is necessary to go through the entire list observing this sequence of operations, shifting each time to i + 1 , without using libraries and adding the result to the end of a[5] . For example:

 a = [220.50,224.68,219.66,224.00, 225.20,231.00,(2),225.00,228.38, 228.90,229.41,223.51,224.47,(1), 231.07,231.07,215.00,216.00, 218.00,224.23,(2),215.71,219.02, 219.50,223.99,215.00,223.99,(2), 223.90,224.50,220.00,221.50, 218.75,221.30,(1)] 

My code is:

 for i in range(len(a)): x = sum(a[0:5]) / 5 y = (2 if a[5] > x else 1 ) print(y) 
  • The condition also says that you need to cut the first 5 elements. And at each iteration you take the same 5 elements, without moving forward on the list - Hive
  • So in this the whole kitchen is that I can not figure out how to move further along the list, each time performing these actions. - SinCap
  • It is necessary to substitute i when making a list cut - a[i:i+5] . And it is worth adding in range step 5 - for i in range(0, len(a), 5): - Andrey
  • @Andrey in your example, in the SECOND iteration, the interpreter begins to add the next five values, starting not with [1], but [2], but [3], and [4], and [5] and comparing ca [6] and t .d .., and c a [5], and [6] a [7], and [8], and [9]. But the code for i in range(0, len(a), 5): is very good implementation of the cycle. Thank you! - SinCap 8:04 pm

0