Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding Consonants?
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020