Skip to main content

python program to to sum the number of list except number between specific range


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
lst=list(map(int,input("Enter number seperated by space ").split()))
s=0
try:
    in6=lst.index(6)
    in7=lst.index(7)
except ValueError:
    in6=1;in7=0
    
if in6<in7:
    
    for i in range (in6):
        s+=lst[i]
    for j in range ((in7+1),len(lst)):
        s+=lst[j]
else :
    s=sum(lst)
print("sum=",s)        
        

Comments