857 views
3 votes
Write a program to find the total ASCII value of vowels in a given string (one word / a phrase / a sentence). The ASCII value of vowels in the given string is calculated by adding the ASCII value of all the vowels in the string. Also, display the individual count of each vowel( number of times each and every vowel appears in the string.

1 Answer

6 votes

In python 3:

def vowelAscii(txt):

vowels = "aeiouAEIOU"

total = 0

lst = ([])

for i in txt:

if i in vowels:

total += ord(i)

if i not in lst:

lst.append(i)

print(f"{i} appears {txt.count(i)} time(s) in the string with an individual ASCII value of {ord(i)}")

return f"The total ASCII value of the vowels in {txt} is {total}."

print(vowelAscii("hello, I'm learning python"))

This is what I managed to come up with. The last line is testing the function. If you need anymore help, just ask. Best of luck.

User Peter Lang
by
7.6k points