Answer the question
In order to leave comments, you need to log in
How to make it so that it takes elements from the list in a loop?
The question is insanely simple, but I don't have the knowledge to do what I'm asking.
ESSENCE OF THE QUESTION: There is a list, it has 25 elements. I need to have a cycle that will take 1,2,3 elements and divide them by 3. For example, it takes 1,2,3 and divides them by 3, then 2,3, 4 and again divides by three; 3, 4, 5 and again on the 3rd division. 4, 5, 6 and again by 3 division, so all 25 elements
Answer the question
In order to leave comments, you need to log in
mylist = list(range(1, 26)) # Делаем массив с элементами от 1 до 25
m = [] # Делаем пустой массив куда будем заносить результаты
for n in range(23):
sum_ = mylist[n] + mylist[n + 1] + mylist[n + 2] # Сумма 3 подряд идущих элементов от n
m.append(sum_ / 3) # Добавление результата
print(m)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question