Answer to Question #309498 in Python for Manish

Question #309498

Math Quiz

Riya took part in a maths quiz competition. To win the prize money she has to solve a tricky question at the end.For a given list of integers, write a program where all the integers in a given index range to be added.

She will be given M multiple ranges, where she should print the sum of numbers for each corresponding range.


Note: The limits in the range are both inclusive.


Input

The first line f input is space-separated integers.

The second line of input is a positive integer M denoting the number of index ranges.

The next M lines contain two space-separated integers of the range.


Output

The output should be M lines.

Each line contains an integer that represents the sum for the corresponding ranges.


Sample Input1

1 3 4 5 6

5

3 5

Sample Output1

12


1
Expert's answer
2022-03-12T04:55:46-0500
s = (str(input("Enter numbers separated by space in ascending order: "))).split(" ")
Nums = []
for r in range(0,len(s)):
    Nums.append(int(s[r]))
x = int(input("Enter from list, lower number a: "))
y = int(input("Enter from list, upper number b: "))
Sum = 0
i1=0
i2=0
for r in range(0,len(Nums)):
    if(Nums[r]==x): i1=r
    if(Nums[r]==y): i2=r


for r in range(i1,i2+1):
    Sum = Sum + Nums[r]
print("Output = ",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