Use Python Based on chapter 5 Functions NOTE that these fun
Use Python: Based on chapter 5 - Functions. NOTE that these functions will not have any INPUT or OUTPUT statements. Note the string can have spaces in it. Notice that the functions themselves just perform the operations, they won’t have an INPUT statement or an OUTPUT statement.
1.Write a function that returns true if a given character is a vowel. This function accepts a character and returns true or false based on the condition.
2.Write a function to return the number of vowels (a, e, i, o, and u) in a sentence. The function accepts the string as a parameter. Make sure to use the above function inside this function.
3.Write a function to return the number of punctuation marks (comma (,), dot (.), question mark (?) and exclamation mark(!) in a given sentence. The function accepts the string as a parameter.
4.Write a function to return the number of digits (0-9). The function accepts the string as a parameter. DO NOT use a pre-defined Python function for this operation. Write your own code here.
5.Call your function(s) and show how they’re used on an input string. Make sure to show the usage of all your functions.
Solution
1.Write a function that returns true if a given character is a vowel. This function accepts a character and returns true or false based on the condition.
def vowel_check(char):
 if char not in(\'aeiouAEIOU\'):
 return False
 return True
2.Write a function to return the number of vowels (a, e, i, o, and u) in a sentence. The function accepts the string as a parameter. Make sure to use the above function inside this function.
VOWELS = [\'a\', \'e\', \'i\', \'o\', \'u\']
 def count(string):
    count = 0
    i = 0
    while i < len(string):
        if string[i] in VOWELS:
            count += 1
        i += 1
    return count
3.Write a function to return the number of punctuation marks (comma (,), dot (.), question mark (?) and exclamation mark(!) in a given sentence. The function accepts the string as a parameter.
PUNCTUATIONS = [\',\', \'.\', \'?\', \'!\']
 def count(string):
    count = 0
    i = 0
    while i < len(string):
        if string[i] in PUNCTUATIONS:
            count += 1
        i += 1
    return count
4.Write a function to return the number of digits (0-9). The function accepts the string as a parameter. DO NOT use a pre-defined Python function for this operation. Write your own code here.
DIGITS = [\'0\', \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\']
 def count(string):
    count = 0
    i = 0
    while i < len(string):
        if string[i] in DIGITS:
            count += 1
        i += 1
    return count


