0
First, my doubt is precisely on how to assemble the data structure (VOWELS and VALUES), ie, what is the best way to assemble the data "vowels" and their respective "values"? Or, what structure to use? (list, dictionary, tuple,....)
Second, how to count the numerical values assigned to the vowels if the word typed contains the vowels?
At this link (Count vowels and know how many there are) as suggested by the colleague in the previous version of my question, shows how to count vowels, but in this case I propose, vowels do not necessarily need to be counted, but only identified/read in the typed word, and its value added to the others present, no matter whether the vowel is repeated or not.
So vowels will have values, for example:
each vowel has an assigned value
vogais = ['a' = 1, 'e' = 2, 'i' = 3, 'o' = 4, 'u' = 5]
BS:(I don’t know how to put together this structure of correspondence between vowels and values: a list of vowels and a list of numbers? a dictionary? tuple? only common variables?
inserting the word
palavras = input("digite uma palavra:" )
Suppose the word "library"
Then it would be something like this:
Leia cada vogal da palavra: #devo usar list()?
valor da vogal = 0
Se vogal estiver em palavra:
valor da vogal + valor da vogal
senão:
print(valor da vogal)
You can do it like this:
saida = [vogais[c] for c in palavras if c in vogais]
and if it does:print(saida)
will have the result:[3, 1]
and to add:print(sum(saida))
will have the result:4
– NoobSaibot
I understood what you suggested, but it didn’t work, probably because of my variable VOWELS, I don’t know how to assemble this string structure to receive an integer value, I will edit the question again specifying better. Thanks in advance.
– Kabann
It didn’t work because it was wrong instead of
vogais = ['a' = 1, 'e' = 2, 'i' = 3, 'o' = 4, 'u' = 5]
has to be dictionaryvogais = { 'a': 1, 'e': 2, 'i': 3, 'o': 4, 'u': 5 }
– NoobSaibot
Thank you very much Noobsaibot!!!!
– Kabann