Help with finding vowels - 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: Help with finding vowels (/thread-16407.html) |
Help with finding vowels - nlord7 - Feb-27-2019 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() RE: Help with finding vowels - ichabod801 - Feb-27-2019 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) |