String - Vowels Position Sum
Coding Problem Keys
String - Vowels Position Sum
Problem Statement
The string S is accepted as the input. The program must print the sum of the positions of the vowels in S. If the string does not contain any vowels then print -1.Boundary Condition(s)
2 <= Length of the string S <= 100Input Format
The first line contains the value of String S.Output Format
The first line contains the sum of the positions of the vowels in S.Example Input/Output 1
Input
noseOutput
6
Explanation
The vowels in the string are o and e. The position of o is 2 and the position of e is 4. The sum of the positions = 2 + 4 = 6.
Hence the output is 6.
Example Input/Output 2
Input
xyzOutput
-1Explanation
There are no vowels in the given string S. Hence the output is -1.
Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Python 3 Language
l=list(input().strip())
l.insert(0,"");s=0;count=0
vowels=list("aeiouAEIOU")
for i in range(len(l)):
if(l[i] in vowels):
s+=i;count+=1
if(count==0):
print("-1")
pass
else:
print(s)
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments