Solve the question - Python
Q. You
are given a block of text with different words. These words are separated by
white-spaces and punctuation marks. Numbers are not considered words in this
mission (a mix of letters and digits is not a word either). You should count
the number of words (striped words) where the vowels with consonants are
alternating, that is; words that you count cannot have two consecutive vowels
or consonants. The words consisting of a single letter are not striped -- do
not count those. Casing is not significant for this mission. Here "y"
is also a vowel.
Example 1: "My name is ..." = 3Example 2: "Hello world" = 0Example 3: "A quantity of striped
words." = 1Example 4: "Dog, cat, mouse, bird. Human."
= 3
li = map(str,raw_input().strip(',.').split(' '))
count = 0
v = ['a','e','i','o','u','y']
c = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
for i in li:
d= 0
li1 = list(i)
for j in range(len(li1)):
if len(li1) == 1:
d = -1
break
elif j == len(li1)-1:
break
elif li1[j] in v and li1[j+1] in v or li1[j] in c and li1[j+1] in c:
d = -1
break
else:
continue
if d == 0:
count += 1
print count
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment