Answer in Web Development for ravi #280049
October 24th, 2022
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.
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.
The output should be M lines printing the sum of each indices range.
In the example, the line of the integers is 12233346 and the 2 indices range.
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) maxValue=int(num) sumResult=0 for i in range(0, len(numbers)): number=int(numbers[i]) if(number>=minValue and number<=maxValue): sumResult+=number print(sumResul