how to count values assigned to vowels if these vowels are present in a WORD or TEXT?

Asked

Viewed 58 times

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)

Could someone suggest some material that will teach me how to plot the data so that it will be able to be manipulated? I’m studying algorithms, but I can’t find anything to teach you how to create variables with data in more "complex structures".

  • 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

  • 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.

  • It didn’t work because it was wrong instead of vogais = ['a' = 1, 'e' = 2, 'i' = 3, 'o' = 4, 'u' = 5] has to be dictionary vogais = { 'a': 1, 'e': 2, 'i': 3, 'o': 4, 'u': 5 }

  • Thank you very much Noobsaibot!!!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.