109k views
3 votes
g Write a general-purpose program with a loop and indexed addressing that calculates sum of the values of elements of a DWORD array that are located at multiple of 4 location. For example for the array 1,2,3,4,5,6,7,8,9,10,11,12,13,14

User Danishgoel
by
5.1k points

1 Answer

3 votes

Answer:

def sumD4th(dword):

select = dword[3::4]

print(sum(select))

mylist = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]

sumD4th(mylist)

Step-by-step explanation:

The python program above defines a function called "sumD4th" that accepts a list as its argument. The variable "select" is created which is the subset of the list argument "mylist" containing the index items that is a sum of four. The output of the function is the sum of the items in the "select" list.

User Jamella
by
5.0k points