I want to make a function that takes a string (sentence) as an argument then takes the first word and saves every character that is a konsonant up to the first vowel (including the vowel) and save it in an empty string. Then i want it to take the second one and do the same thing... and so on... and so on...
Ex. input -> "This is good" output -> ThiThiThi iii gogogo
This is what i have came up with so far:
def lang(text):
alist=text.split()
kons="nrmg" nytext=" "
for word in alist:
for tkn in word:
if tkn in kons:
nytext+=tkn
else:
nytext+=tkn
nytext=nytext*3
nytext=nytext+"" break
return nytext
print(lang("This is good"))
what i get is this -> T T Ti T T Ti T T Ti
What am i doing wrong?
Any help is appreciated!
Thanks :)
So the first thing is if you want to keep track of each word differently, then you need to use another variable(I called retText
) because each word should be processed separately and results should be collected in the different variable.
Secondly, if you are looking for finding letters up to first vowel, then you need to check if the letter is vowel or not. kons
variable holds the vowels and inside of the code, there is an
if not tkn in kons:
statement which checks if the tkn is vowel or not. Here is the full code:
def lang(text):
alist=text.split()
kons="aeiouAEIOU"
retText=""
for word in alist:
nytext=""
for tkn in word:
if not tkn in kons:
nytext+=tkn
else:
nytext+=tkn
retText += nytext*3 + " "
break
else:
retText += word*3 + " "
return retText
print(lang("This is good"))