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


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug How to print only vowels from an input? PP9044 8 7,558 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Counting Vowels in Python sapphosvoice 1 3,310 May-05-2020, 04:24 AM
Last Post: buran
  Return not vowels list erfanakbari1 2 2,697 Mar-26-2019, 11:37 AM
Last Post: perfringo
  Functions to remove vowels and extra blanks RiceGum 10 5,873 Nov-17-2017, 05:40 PM
Last Post: heiner55
  Print the index of the vowels in a string MeeranRizvi 4 14,685 Dec-29-2016, 02:43 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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