Question

In: Computer Science

Use the Design Recipe to write a function count_vowels, which consumes a string and returns the...

Use the Design Recipe to write a function count_vowels, which consumes a string and returns the number of vowels in that string. For these purposes, the vowels are a, e, i, o, and u, but never y. Include a Docstring! Note: Count both upper and lowercase vowels! Write 3 assert_equal statements to test your function.

Solutions

Expert Solution

def count_vowels(message):

    """ consumes a string and returns the number of vowels in that string"""

    letter_list = list(message.lower())

    "*** YOUR CODE HERE ***"

    ans=0

    vowel_list=['a','e','i','o','u']

    for letter in letter_list:

        if letter in vowel_list:

            ans+=1

    return ans

    

    

x=str(input("Enter String: "))

y=count_vowels(x)

print("the number of vowels in given string = "+str(y))

******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION
******************************************************************************************


Related Solutions

Use the Function Design Recipe (FDR) to design, code and test the definition of a new...
Use the Function Design Recipe (FDR) to design, code and test the definition of a new function named distance. This function returns the distance between two points, given by the coordinates (x1, y1) and (x2, y2). The function parameters are the x and y values. Need help. Thank you
4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns...
4. Implement the function read_info_file that consumes a file name (string) as its parameter and returns a list of strings - one element for each line in the file. These lines should have all the whitespace removed from both ends of the line. a. See the formatting of the individual_info data file. Consider how a file can be read into the program. In Python language
Use Python Write a function that takes a mobile phone number as a string and returns...
Use Python Write a function that takes a mobile phone number as a string and returns a Boolean value to indicate if it is a valid number or not according to the following rules of a provider: * all numbers must be 9 or 10 digits in length; * all numbers must contain at least 4 different digits; * the sum of all the digits must be equal to the last two digits of the number. For example '045502226' is...
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
write an algorithm function called balance() in javascript that takes in a string and returns a...
write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string...
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string of their sum. *Simply converting strings to numbers and adding them together isn’t acceptable.* The program must be able to handle large decimals. Be sure to touch on these when solving for the solution: Pad the right side Pad the left side Make sure string is same length by putting 0’s where it was missing (be careful w/ decimal points) Make sure to remove...
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string...
Write a function addStrings(string1, string2) that takes in two decimals as strings and returns a string of their sum. *Simply converting strings to numbers and adding them together isn’t acceptable.* The program must be able to handle large decimals. Be sure to touch on these when solving for the solution: Pad the right side Pad the left side Make sure string is same length by putting 0’s where it was missing (be careful w/ decimal points) Make sure to remove...
Use a switch statement to write a function that returns TRUE if a character is a...
Use a switch statement to write a function that returns TRUE if a character is a consonant and returns FALSE otherwise.
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT