forked from vtejapy/Beginners-Python-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvowel_count.py
More file actions
34 lines (29 loc) · 818 Bytes
/
vowel_count.py
File metadata and controls
34 lines (29 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
# The function
# counts number of occurrences of vowels
# in given string
# Principle:
# Loop through list of vowels
# count occurrences of each vowel in given string
# yield/generate the occurrences of that vowel
def vowel_count(S):
vowels = ['a', 'e', 'i', 'o', 'u']
for vowel in vowels:
counter = 0
for char in S:
if char == vowel:
counter += 1
yield(vowel, counter)
# CLI
# Testing or Playing Interface
while True:
usr_input = raw_input("\nPress (e) to Exit\nor Enter string: ").strip().lower()
if not usr_input == "e":
print("> Results: ")
for vow, counter in vowel_count(usr_input):
print(" " + vow + " > occurred " + str(counter) + " times.")
else:
print("\nHope you enjoyed!")
sys.exit()