Knowee
Questions
Features
Study Tools

Define a function named write_words_start_vowel(filename, names) which takes a filename and a list of words as parameters. The function should write the words that start with a vowel from the list to the file specified by the filename parameter. Each line contains one word only. Note:Remember to close the file.You can assume that the parameter list is not empty.The function needs to handle both uppercase and lowercase letters.The print_contents() function is used for marking purposes. You can assume that it is given in CodeRunner. Do not provide its implementation.For example:Test Resultwrite_words_start_vowel('bdon483.txt', ['life', 'is', 'a', 'long', 'journey', 'with', 'problems', 'to', 'solve'])print_contents('bdon483.txt')

Question

Define a function named write_words_start_vowel(filename, names) which takes a filename and a list of words as parameters. The function should write the words that start with a vowel from the list to the file specified by the filename parameter. Each line contains one word only. Note:Remember to close the file.You can assume that the parameter list is not empty.The function needs to handle both uppercase and lowercase letters.The print_contents() function is used for marking purposes. You can assume that it is given in CodeRunner. Do not provide its implementation.For example:Test Resultwrite_words_start_vowel('bdon483.txt', ['life', 'is', 'a', 'long', 'journey', 'with', 'problems', 'to', 'solve'])print_contents('bdon483.txt')

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python function that meets the requirements:

def write_words_start_vowel(filename, names):
    vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    with open(filename, 'w') as f:
        for word in names:
            if word[0] in vowels:
                f.write(word + '\n')

This function first defines a list of vowels, both in lowercase and uppercase. It then opens the file specified by the filename parameter in write mode. For each word in the names list, it checks if the first letter of the word is in the list of vowels. If it is, it writes the word to the file, followed by a newline character. The file is automatically closed when the with block is exited.

This problem has been solved

Similar Questions

Q) Write a program to input a string and convert it into uppercase and print the pair of vowels and number of pair of vowels occurring in the string. Example: Input: "BEAUTIFUL BEAUTIES " Output : Pair of vowels: EA, AU, EA, AU, IE No. of pair of vowels: 5

Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file words.txt to produce the output below.

Write a function, vowelCount() in Python that counts and displays thenumber of vowels in the text file named Poem.txt

letter countWrite a C program that will analyze a line of text and will print the number of words, the number of consonants, and the number of vowels in the text.Testcase:Input:Programming is fun!Output:3      // Number of words:11   // Number of consonants:5   // Number of vowels:

Words, Vowels and ConsonantsProblemSubmissionsLeaderboardGiven a sentence containing only uppercase/lowercase english alphabets and spaces, you have to count the number of words, vowels and consonants.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a single sentence.Constraints1 <= T <= 10001 <= len(sentence) <= 104Output FormatFor each test case, print the number of words, vowels and consonants, separated by newline.Sample Input 04HiHello World Exception Hi thereSample Output 01 1 12 3 71 4 52 3 4

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.