Python Forum

Full Version: Help with finding vowels
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im fairly new to programming, so apologies for the silly mistakes. Im trying to find words with 10 or more vowels in them given a .txt file. However, the output only outputs what my num_of_v == value is. so ill type in 10 and get all the words with 10 characters. 5 and words with 5 characters. I realize this is where my issue is, im just having trouble incorporating the word[i] to get just the words with 10 vowels.

any help would be appreciated. Thanks





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


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


def get_vowels(word):
    num_of_v = 0
    for i in range(len(word)):
        if word[i] == 'a' or 'e' or 'i' or 'o' or 'u' or 'y' and not 'w':
            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 get_vowels(word):
            print(word)


print_two_words()
You need to have an expression on each side of the or (see here for details)

Also, you should loop over fin directly:

def print_two_words():
    for line in open(r'\\scrabble\words.txt'):
        if get_vowels(line.strip()):
            print(word)