Question: need help please a) Write a complete definition for a function named count_char that meets these specifications: - Accepts a string s as an input
a) Write a complete definition for a function named count_char that meets these specifications: - Accepts a string s as an input argument and a single character ch as another input argument. - Uses a for loop to do the following: - Counts the number of times that the character stored in ch appears in the string. Note that it has to be an exact match, i.e., upper- and lower-case versions are considered different. - Counts the number of times that a digit character ( 6 ' through ' 9 ') appears in the string. Note: You are NOT allowed to use the string. count (s) library function! - Returns both counts back to the caller. - The function should be silent. This means the function itself does not prompt for data, and it does not print anything. Sample results: Argument s is "Hello, John" and ch is " 0 ' number of ' 0 " is 2 and number of digits is 0 Argument s is " 1-2-5Ae@c-aT" and ch is " k ' number of ' k ' is 0 and number of digits is 3 Argument 5 is "K-E-E-P easy 3 " and ch is ' E ' number of ' E ' is 2 and number of digits is 1 Argument s is "alpha+bravo" and ch is ' M ' number of ' M ' is 0 and number of digits is 0 Write your function code in the box below. b) Suppose the main section of a Python script prompts the user to enter the needed arguments like this: my_str = input("Please enter string: ") my_ch = input("Please enter character: ") Write a single line of code in the box below that shows how you would call (or invoke) your function, pass it the string and character variables, and store the values retumed by the function for later use
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
