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
[Please test the sample test cases and send the screenshots].
#first
def question(f: int,i ):
i = input(f).split()
f =list(map(int, i))
return f, f[-1],
print(question(0,0))
#second
n=int(input('no1 :'))
gross=0
no=0
while no < n:
no+=1
gross+=no
n1=int(input('no2 :'))
gross1=0
no1=0
while no1 < n1:
no1+=1
gross1+=no
print('total :',gross+gross1)
Comments
Leave a comment