Question

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, u, appear, respectively, 3, 2, times.

>>>lab5.vowelCount2(‘universities’)

e, i, u, appear, respectively, 2, 3, 1, times.

>>>lab5.vowelCount2(‘kkk’)

>>>lab5.vowelCount2(‘crypto’)

o, appear, respectively, 1, times

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def vowelCount2(s):
    d = {}
    for ch in s:
        if ch in "aeiouAEIOU":
            ch = ch.lower()
            if ch not in d:
                d[ch] = 0
            d[ch] += 1
    chars = []
    values = []
    for ch, count in sorted(d.items()):
        chars.append(ch)
        values.append(str(count))
    if len(d) > 0:
        print('{}, appear, respectively, {}, times.'.format(', '.join(chars), ', '.join(values)))

# Testing the function here. ignore/remove the code below if not required vowelCount2(augustana) vowelCount2(universities

\color{red}\underline{Output:}

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

Add a comment
Know the answer?
Add Answer to:
Write function vowelCount2() 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 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.

  • 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...

  • Write a function that will accept an array of string. Return the index of the element...

    Write a function that will accept an array of string. Return the index of the element that has the most vowels. For this exercise, vowels are a,e,i,o, and u. If none of the strings contain a vowel, return -1. If two or more words contain the same largest amount of vowels, either index of such words is acceptable. (using C++)

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • Write a Haskell function piglatinize that returns a word into its piglatin form: if it begins...

    Write a Haskell function piglatinize that returns a word into its piglatin form: if it begins with a vowel, add to the end "yay", else move non-vowels to the end of the string until a vowel is at the front and then add to the end "ay". The word arguments are guaranteed to have a vowel (a, e, i, o, or u) and not begin with the letter y. piglatinize :: String -> String

  • 2) Write a function stringManip that takes in a character string and returns a character string...

    2) Write a function stringManip that takes in a character string and returns a character string following these rules: a) any vowel (a, e, i, o, u) is replaced by the character '&' b) any numeric character has 1 added to it (if it was 9, it becomes O instead) (str2num() is useful here) c) all lowercase characters become uppercase d) replace the final character with '!' e) append the length of the string before this step to the end...

  • // 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...

  • Your task is to write a function definition for a function named non_vowel_words that takes a...

    Your task is to write a function definition for a function named non_vowel_words that takes a string as a parameter.  The function returns a setcontaining the words of the strings that do not start with a vowel (upper or lower case). The vowels are A, E, I, O, U. For full credit, make sure your implementation is pythonic, uses Python built-in capabilities and follows the Python style guide recommendations.  Please include a docstring for your function. You may test your function as...

  • IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption...

    IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption defined as follows: Every character at an odd position i in the alphabet will be encrypted with the character at position i + 1, and every character at an even position i will be encrypted with the character at position i - 1. In other words, ‘a’ is encrypted with ‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’, with ‘c’, and so on. Lowercase...

  • 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