Python Forum

Full Version: Finding Consonants?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im working on this project to get the only two words in a .txt file that have 10 vowels in it and 6 words that have 6 or more consonants in a row (which is unbroken by vowels) I feel i get can the logic for getting just consonants, but dont know where to start with the logic to get them in a row. Any help would be appreciated. Im fairly new to programming so thanks for any help.

fin = open('\\scrabble\words.txt')

print(fin)


def get_a_word():
    line = fin.readline()
    word = line.strip()
    return word


def ten_vowels(word):
    num_of_v = 0
    for i in range(len(word)):
        if word[i] in 'aeiouy':
            num_of_v = num_of_v + 1

    if num_of_v == 10:
        return True
    else:
        return False


def print_two_words():
    for i in range(113810):
        word = get_a_word()
        if ten_vowels(word):
            print(word)




print_two_words()
To find a word with 6 consonants, count the consonants, but every time you run into a vowel, reset the count to zero. As soon as you get to 6 consonants, stop.