I am trying to add certain text everytime a vowel appears in a word. Here is my code so far:
first_syl = 'ab'
second_syl = 'bc'
word = 'income'
vowels = "aeiou"
diction = "bcdfghjklmnpqrstvwxyz"
empty_str = ""
word_str = ""
for ch in word:
if ch in diction:
word_str += ch
if ch in vowels:
empty_str += word_str + ch + first_syl
print (empty_str)
Result – iabncoabncmeab
Correct Result – iabncoabmeab
The difference is that in my program there is an extra ‘nc’ right before ‘meab’. The problem is when the loop runs it adds first ‘n’, then ‘nc’, then ‘ncm’ (non vowels) but instead I need it to add ‘n’, then ‘c’, and then ‘m’.
Any ideas on how to do this..? Using python 3.2.3, thanks.
Not sure what you try to do but if your goal is to obain
iabncoabmeab
Then you need to reset word_str after a vowel appears