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)
iwhen making a list cut -a[i:i+5]. And it is worth adding inrangestep 5 -for i in range(0, len(a), 5):- Andreyfor i in range(0, len(a), 5):is very good implementation of the cycle. Thank you! - SinCap 8:04 pm