0

Given a list of integers, how to obtain the product of all the even-indexes integers?

number_list = [1,2,3,4,5,6,7,8,9,10]

25th Oct 2018, 4:04 PM
Nah Wei Siang
Nah Wei Siang - avatar
3 Antworten
+ 3
So you loop by all the list elements checking if the element is even ( if is divisible by 2). If it is you keep it in a variable. after that you continue checking but you will multiply with last value acquired and keep it. You will do that until you finish checking the last element of the list.
25th Oct 2018, 4:23 PM
Anya
Anya - avatar
0
Nah Wei Siang In your reply to Anna's code, you asked for even numbers, but here you asked for even index, they are different. Also, if you do not know the different in advance, you have to use modulus num[i]%2 as Anya has said. If you are still here and still wants to know the answer, reply, and I'll explain.
27th Oct 2018, 6:00 PM
Gordon
Gordon - avatar