Tuesday, March 27, 2012

exercise 9.5 - uses_all


"""=============================
exercise 9.5
============================="""

def uses_all (word, use_all_chars):
    for char in use_all_chars:
        if char.lower() not in word.lower():
            if char != " ": #ignore space character
                return False
    return True
    
#print uses_all("Ho ho ho","acefhlo")
#print uses_all("Flo ace hoe","acefhlo")

fin = open('words.txt')

use_all_vowels = "aeiou"
use_all_vowels_and_y = "aeiouy"

for line in fin:
    word = line.strip()
    if uses_all(word,use_all_vowels):
        print word
        vowels = vowels + 1
    if uses_all(word,use_all_vowels_and_y):
        print word
        vowels_and_y = vowels_and_y + 1
    total_words = total_words + 1

print "number of words with aeiou = ",vowels
print "number of words with aeiouy = ",vowels_and_y

2 comments:

Note: Only a member of this blog may post a comment.