Math Quiz
Write a program to print the following,
Sample Input 1
1 3 4 5 6
5
3 5
Sample Output1
12
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)
Python Output:
Enter numbers separated by space in ascending order: 1 3 4 5 6
Enter from list, lower number a: 3
Enter from list, upper number b: 5
Output = 12
>>>
Comments
Leave a comment