Answer to Question #349407 in Python for Hari

Question #349407

given a list of M numbers and a positive integer N, print the sum of numbers whose position in the list is divisible by N. consider that the positions of numbers range from 1 to N.

Explanation : Given N = 1, M= 7 and the numbers_list = [4, 8, 6, 6, 7, 9,3]

as every position is divisible by 1, 4+8+6+6+7+9+3=43

so, output is 43

Input : 1 7

4 8 6 6 7 9 3

Output : 43

Input : 4 13

7 3 10 4 5 8 4 9 6 9 10 1 4

Output : 14


1
Expert's answer
2022-06-09T09:58:29-0400
N_M_lst = list(input().split())
N = int(N_M_lst[0])
M = int(N_M_lst[1])
number_lst = list(input().split())
number_lst = [int(i) for i in number_lst]
sum = 0
for i, item in enumerate(number_lst, 1):
    if i % N == 0:
        sum += item
print(sum)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS