Question
5) Like Q4 above, this time, the program counts the number of words that starts with a user-entered character. Instead of exiting after each entry,
5) Like Q4 above, this time, the program counts the number of words that starts with a user-entered character. Instead of exiting after each entry, a user can enter a letter repeatably until a 9 is entered Result string = It is very hot and humid in Memphis in the Summer but not in Seattle enter the character that you want to count in the string i there are 4 char "i" in the string try a different char, enter 9 to exit enter the character that you want to count in the string S there are 2 char "S" in the string try a different char, enter 9 to exit enter the character that you want to count in the string h there are 2 char "h" in the string try a different char, enter 9 to exit enter the character that you want to count in the string 9 done
Write a program to count the number of occurrences of a user-entered character within a string.
For this exercise, use the .split( ) method to create a list that each word is a list item.
Write a function (count (st, x) where st is the string, and x is the user-entered character
count(st, x) returns the number of occurrences of the character entered.
For example
st = "This is very hot and humid in Memphis"
x = user entered (using input( enter the character that you want to count in the string)
Pass this string (st) to count(st, x)
Result:
string = This is very hot and humid in Memphis
enter the character that you want to count in the string
h
there are 4 char "h" in the string
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started