Q:

Write a Python program to calculate the sum of the numbers in a list between the indices of a specified range

0

Write a Python program to calculate the sum of the numbers in a list between the indices of a specified range

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def sum_Range_list(nums, m, n):                                                                                                                                                                                                
    sum_range = 0                                                                                                                                                                                                         
    for i in range(m, n+1, 1):                                                                                                                                                                                        
        sum_range += nums[i]                                                                                                                                                                                                  
    return sum_range   

nums = [2,1,5,6,8,3,4,9,10,11,8,12]
print("Original list:")
print(nums)
m = 8
n = 10
print("Range:",m,",",n) 
print("\nSum of the specified range:")
print(sum_Range_list(nums, m, n))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now