Answer to Question #280049 in Web Development for ravi

Question #280049

sum of Ranges

Given a space-seperated list of integers as integers as input, write a program to and the elements in the given range and print their sum.

You you will be given M multiple range questions, where you should print sum of members that belong to the corresponding range.


Input

The first of input is space-separated integers.

The second line of input is a positive integer M denoting the nuber of quiries.

The next M lines contain two space-seperated integers.


output

The output should be M lines printing the sum of each indices range.


Explanation

In the example, the line of the integers is 12233346 and the 2 indices range.

0 2

1 4


1
Expert's answer
2021-12-16T04:50:17-0500
numbers = input().split(" ")
numberQueries=int(input())
rangeNumbers=[]
for ​i in range(0, numberQueries):
    rangeNumbers.append(input())


for ​i in range(0, numberQueries):
    num=rangeNumbers[i].split(" ")
    minValue=int(num[0])
    maxValue=int(num[1])
    sumResult=0
    for i in range(0, len(numbers)):
        number=int(numbers[i])
        if(number>=minValue and number<=maxValue):
            sumResult+=number
    print(sumResul




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
APPROVED BY CLIENTS