4
I’d like to ask for your help. I have a code in Python where a part is missing: parse the words of a sentence and save the ones that have an even number of vowels.
Example: "I came home and went to play video games". The word "I arrived" has 4 vowels, 4 is even so I need to keep it in a list.
I want to do this with all the sentences read and then rewrite them inside the list.
Incomplete code:
def frases():
vog="aeiou"
dig="0123456789"
sd=0
sv=0
vp=[]
f = str(input('Digite uma frase: ')).lower()
while f != '':
vp = f.split()
for a in range(len(vp)):
for l in vp[a]:
if l in vog:
sv+=1
for d in vp[a]:
if d in dig:
sd += 1
print('Palavras contidas na frase: {}'.format(len(vp)))
print('Total de vogais: {}'.format(sv))
print('Total de dígitos: {}'.format(sd))
print()
f = str(input('Digite uma frase: ')).lower()
frases()
It was almost, the problem is that it adds words that have no vowel. Take the test if you want, example phrase "call 2444-5000", It will add up to the number in the list.
– user122202
@user122202 see now with editing. If you want to add words without repeating them, you can also add
and palavra not in palavras_vogais_pares
.– AlexCiuffa
Thanks for the help. The only problem now is that the list (palavras_vogais_pairs) contains the words with vowels for all phrases. I would need a list for each. Example: list1 with the vowel words of the first sentence. Lista2 with the words of the second sentence.
– user122202
@user122202 search on matrices then.
– AlexCiuffa