Python Forum
Finding Consonants? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Finding Consonants? (/thread-16430.html)



Finding Consonants? - nlord7 - Feb-28-2019

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()



RE: Finding Consonants? - ichabod801 - Feb-28-2019

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.