'''
Created on Sep 22, 2014

@author: Susan
'''



def isVowel(char):
    return char.lower() in 'aeiou'



# THIS CODE IS BAD> LOTS OF PROBLEMS
def countOfLetterThreeTimes(title, letter):
    # return true if letter occurs in title at least three times
    # scan the word character by character in a while loop 
    # why doesn't this work?
    count = 0
    pos = 0
    while (count < 3 ):
        if title[pos] == letter:
            count += 1
        pos += 1
    return True

def countOfLetterThreeTimes2(title, letter):
    # return true if letter occurs in title at least three times
    # scan the word character by character in a while loop 
    # why doesn't this work?
    count = 0
    pos = 0
    while (count < 3 ) and pos < len(title):
        if title[pos] == letter:
            count += 1
        pos += 1
    if count == 3:
        return True
    return False

def countOfLetterThreeTimes3(title, letter):
    # return true if letter occurs in title at least three times
    # scan the word character by character in a while loop 
    # why doesn't this work?
    count = 0
    pos = 0
    for i in range(0, len(title)):
        if title[i] == letter:
            count += 1
        if count >= 3:
            return True
    return False  

def countOfLetterThreeTimes4(title, letter):
    # return true if letter occurs in title at least three times
    # scan the word character by character in a while loop 
    # why doesn't this work?
    return title.count(letter) >= 3


# Now return the phrase from the beginning until 
# the word that has the third letter
def phraseThroughWordWithThirdLetter(title, letter):
    count = 0
    pos = 0
    while (count < 3 ) and pos < len(title):
        if title[pos] == letter:
            count += 1
        pos += 1    
    # now find the rest of the last word
    # important that pos < len(title) is first in the condition
    while (pos < len(title) and title[pos] != " "):
        pos += 1
    return title[:pos]

title = "the goose is on the loose that is it"
print countOfLetterThreeTimes2(title, "o")
print countOfLetterThreeTimes2(title, "z")

print phraseThroughWordWithThirdLetter(title, "o")
print phraseThroughWordWithThirdLetter(title, "e")
print phraseThroughWordWithThirdLetter(title, "t")
print phraseThroughWordWithThirdLetter(title, "s")
print phraseThroughWordWithThirdLetter(title, "z")


