import random def generate_array(): alphabetstring = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" twohundredchars = [] alphabetstring.split() count = 200 while count != 0: twohundredchars.append(random.choice(alphabetstring)) count -= 1 return twohundredchars def vowel_counter(twohundredchars): a_count = 0 e_count = 0 i_count = 0 o_count = 0 u_count = 0 for char in twohundredchars: if char.lower() == "a": a_count += 1 elif char.lower() == "e": e_count += 1 elif char.lower() == "i": i_count += 1 elif char.lower() == "o": o_count += 1 elif char.lower() == "u": u_count += 1 return { "a_count": a_count, "e_count": e_count, "i_count": i_count, "o_count": o_count, "u_count": u_count, "total": a_count + e_count + i_count + o_count + u_count } myArray = generate_array() vowel_count = vowel_counter(myArray) print('Array is: {}'.format(', '.join(myArray))) print('Number of a: %s' % vowel_count["a_count"]) print('Number of e: %s' % vowel_count["e_count"]) print('Number of i: %s' % vowel_count["i_count"]) print('Number of o: %s' % vowel_count["o_count"]) print('Number of u: %s' % vowel_count["u_count"]) print('Total vowels: %s' % (vowel_count["total"]))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question