Answer to Question #346024 in Python for spike

Question #346024

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


INPUT:

the first line contains two-spaced integers N,M

the second line contain M space-seperated integers.


output:

print a single integer representing the requried sum


explanation:

Sample Output1

Given N=1 , M=7

and the number_list=[4,8,6,6,7,9,3]

As every position is divisible by1,

4+8+6+6+7+9+3=43

so the output should be 43


1
Expert's answer
2022-05-30T08:16:53-0400
n, m = input().split()
n, m = int(n), int(m)
number_list = [int(i) for i in input().split()]
s = 0
for i in range(m):
    if (i+1) % n == 0:
        s += number_list[i]
print(s)

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