Python 3.6 Question 13a (10 points) The letters a, e, i. o and u are vowels. No
ID: 3715615 • Letter: P
Question
Python 3.6
Question 13a (10 points) The letters a, e, i. o and u are vowels. No other letter is a vowel. Write a function named vowelCount) that takes a string. s, as a parameter and returns the number of vowels that s contains. The string s may contain both upper and lower case characters. For example, the function call vowelCount('Amendment) should return the integer 3 because there are 3 occurrences of the letters 'A' and 'e' Question 13b (10 points) Write a function named manyVowels() that takes a body of text, t, and an integer, i, as parameters. The text t contains only lower case letters and white space. manyVowels() should return a dictionary in which the keys are all words in t that contain at least i vowels. The value corresponding to each key is the number of vowels in it. For full credit, manyVowels() must call the helper function vowelCount) from Question lla to determine the number of vowels in each word. For example, if the input text contains the word "hello". then "hello" should be a key in the dictionary and its value should be 2 because there are 2 vowels in Input: 1. t, a text consisting of lower case letters and white space 2. i. a threshold number of vowels Return: a dictionary of key-value pairs in which the keys are the words in t containing at least i vowels and the value of each key is the number of vowels it contains. For example, the following would be correct output. text 'they are endowed by their creator with certain unalienable rights print (manyVowels(text, 3)) certain': 3, unalienable': 6, 'creator': 3. 'endowed 3)Explanation / Answer
ScreenShot
--------------------------------------------------------------------------------------------------------
Question 13.a
Program
#function definition
def vowelCount(str):
#variable to get vowel count
vowels=0
#loop to get each charcters in the string
for i in str:
#if matched then increment vowelcount value
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):
vowels=vowels+1
#return count
return vowels
#prompt user for input the string
inputString=input("Enter string:")
#call function and print result
print("Number of vowels are:",vowelCount(inputString))
-------------------------------------------------------------------------------------------------------------------------------
Question 13.b
Program
#package used to split the text
import re
#function definition
def manyVowels(text,count):
#variable to get vowel count
vowels=0
#dictionary for store words greater than the parameter count
vowelsCount={}
#list to split text words
wordList=[]
#split and store words
wordList = re.sub("[^w]", " ", text).split()
#loop through each word
for word in wordList:
#loop through each character of the word
for j in word:
#match and increment vowel count
if j=='a' or j=='e' or j=='i' or j=='o' or j=='u':
vowels=vowels+1
#If count greater than parameter count add tht word in dictionary
if vowels>=count:
vowelsCount[word]=vowels
vowels=0
#return dictionary
return vowelsCount
#prompt user for input the string
inputText=input("Enter text:")
#call function and print result
print("Number of vowels are:",manyVowels(inputText,3))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.