Tuesday, March 27, 2012

exercise 9.3 - avoids


"""=====================
exercise 9.3
====================="""

def avoids(word, forbidden_chars):
    letter = ""
    forbidden_char = ""
    
    for letter in word:
        if letter.lower() in forbidden_chars.lower():
            return False
    
    return True
# end def avoids ()

avoid_chars = raw_input()
total_words = 0

fin = open('words.txt')

for line in fin:
    word = line.strip()
    if avoids(word,avoid_chars):
        print word
        words_that_avoid = words_that_avoid + 1
    total_words = total_words + 1

total_unavoided = total_words - words_that_avoid

print total_unavoided

1 comment:

  1. Thanks for this. words_that_avoid needs to be defined so I added a couple lines like so:

    print "List some characters to avoid:"
    avoid_chars = raw_input()
    total_words = 0
    words_that_avoid = 0

    ReplyDelete

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