You are given a list of numbers from 1 to 9, in which each word is seperated by ‘,’. Your job is to find the sum of two numbers. These two numbers are needed to be calculated as per following rules :
1. First number should be calculated as :
Add all the numbers that do not come between 5 and 8 in the input.
2. Second number should be calculated as :
Append all the numbers to each other that comes between 5 and 8 (inclusive).
Find the sum of both numbers.
Note : 5 always comes before 8.
Number of 5’s = Number of 8’s.
First Input : List of numbers
“Sum of both numbers”
Sample Testcases :
#taking list as input where each element is seperated by ',' lst = list(map(int,input().split(","))) #find sum of numbers that occur before 5 a = sum(lst[:lst.index(5)]) #find sum of numbers that occur after 8 b = sum(lst[lst.index(8)+1:]) #finding first number n1 = a+b #finding second number rest = lst[lst.index(5):lst.index(8)+1] n2 = "" for i in rest: n2+=str(i) print(int(n2)+n1)