Question

Write function vowelCount() that takes a string as input and counts and prints the number of...

Write function vowelCount() that takes a string as input and counts and prints the

number of occurrences of vowels in the string.

>>> vowelCount('Le Tour de France')

a, e, i, o, and u appear, respectively, 1, 3, 0, 1, 1 times.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def vowelCount(s):
    a, e, i, o, u = 0, 0, 0, 0, 0  # initialize all counts to 0
    for ch in s:
        ch = ch.lower()  # take a character from string
        if ch == 'a':  # if character is a
            a += 1  # then increase a by 1
        elif ch == 'e':  # if character is e
            e += 1  # then increase e by 1
        elif ch == 'i':  # if character is i
            i += 1  # then increase i by 1
        elif ch == 'o':  # if character is o
            o += 1  # then increase o by 1
        elif ch == 'u':  # if character is u
            u += 1  # then increase u by 1
    # print result
    print("a, e, i, o, and u appear, respectively, "
          + str(a) + ", " + str(e) + ", " + str(i) + ", " + str(o) + ", " + str(u) + " times.")


# Testing the function here. ignore/remove the code below if not required
vowelCount("Le Tour de France")

Add a comment
Know the answer?
Add Answer to:
Write function vowelCount() that takes a string as input and counts and prints the number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write function vowelCount2() that takes a string as input and counts and prints the number of...

    Write function vowelCount2() that takes a string as input and counts and prints the number of occurrences of vowels in the string. Vowels are a, e, i, o, and u. Implement the code in the file lab5.py. This function is very similar to the function of the problem 4.25, but the vowel information which did not appear in the string should not be printed. The printing order of the vowels is a, e, i, o, u. e.g.) >>> lab5.vowelCount2(‘augustana’) a,...

  • Write a basic ARM program that takes a string as input, then outputs a string that...

    Write a basic ARM program that takes a string as input, then outputs a string that replaces all the vowels in the input string with 'x'. Vowels: a, A, e, E, i, I, o, O, u, U. **I am using DS-5 Eclipse Community Workspace with ARM assembly language.** The program should give the following input prompt: "Input a string: " Then, the program should output the string with the vowel(s) replaced with x. The program should terminate upon printing the...

  • JAVA Array 3. Write a method called noVowels that takes a String as input and returns...

    JAVA Array 3. Write a method called noVowels that takes a String as input and returns true if it doesn't contain any vowels (a, e, i, o, u)

  • Write a function vowelCount(S) that takes a string, S, and returns a new dictionary containing entries...

    Write a function vowelCount(S) that takes a string, S, and returns a new dictionary containing entries of the form v:N where v is one of ’aeiou’ and N is the number of occurrances of v in S.Your dictionary should never contain any entries where N is 0; thus, for example, if the S is "wipeout", the dictionary returned would be {′e′:1,′i′:1,′o′:1,′u′:1 }and not {′a′:0,′e′:1,′i′:1,′o′:1,′u′:1}. NOTE: must use a comprehension

  • Write a Pelles C program that takes a char array (string) and counts the number of...

    Write a Pelles C program that takes a char array (string) and counts the number of consonants and vowels using a pointer

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

  • By using Java public static methods solve following problem Write a method called vowelCount that accepts...

    By using Java public static methods solve following problem Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Write a python program that does the following: takes as input from the user an English...

    Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...

  • Write a function count_vowels(s) that takes a string as an argument and returns the number of...

    Write a function count_vowels(s) that takes a string as an argument and returns the number of vowels ('a', 'e', 'i' 'o', 'u') in the string. Should you use a for or while loop? (Implement this as a function, not as a class with a method.) Be sure to include unittest test cases to demonstrate that your code works properly, e.g Part 2: last_occurance(target, sequence) Write a function last_occurance(target, sequence) that takes two arguments: 1. target: A target item to find...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT