← Projects

Count vowels done

9a41dc496f560115adddf33dd76b666a8444cf2a · Karan Goel · Jul 11, 2013 17:13

+17 · 1 file changed

  • Text/count_vowels.py +17 −0
diff --git a/Text/count_vowels.py b/Text/count_vowels.py
new file mode 100644
index 0000000..8477648
--- /dev/null
+++ b/Text/count_vowels.py
@@ -0,0 +1,17 @@
+"""
+Count Vowels - Enter a string and the program counts
+the number of vowels in the text. For added complexity
+have it report a sum of each vowel found.
+"""
+
+string = raw_input('Enter a string: ').lower()
+
+vowels = ['a', 'e', 'i', 'o', 'u']
+counts = dict(zip(vowels, [0, 0, 0, 0, 0]))
+
+for vowel in counts:
+    for char in string:
+        if vowel == char:
+            counts[vowel] += 1
+
+print counts