Question: URGENT, INTRO/BASIC PYTHON PROGRAM - THUMBS UP WILL BE GIVEN? There are times when a program has to search for and replace certain characters in

URGENT, INTRO/BASIC PYTHON PROGRAM - THUMBS UP WILL BE GIVEN?

There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It will then perform various functions such as replacing the key character with an asterisk (*) wherever it occurs in the target string. For example, if the key character were

'a'

and the string were

"He who laughs last, laughs fast, faster, FASTEST."

then the operation of replacing the 'a' by an asterisk would result in the new string:

"He who l*ughs l*st, l*ughs f*st, f*ster, FASTEST."

As you can see, only the lower-case 'a' was detected and replaced. This is called "case-sensitivity" and this entire program spec is case-sensitive.

This was only one possible task we might perform. Another would be to remove all instances of the key character rather than replace each with an asterisk. Yet a third might be to count the number of key characters.

Ask the user to enter both a key character and a target string (phrase, sentence, etc.). Then, show the user three things:

1. The target string with the key character replaced by asterisks. 2. The target string with the key character removed. 3. The number of occurrences of the key character (case sensitive) in the target string.

This program does not loop for different strings. Once it processes a string, the program ends. Here, "character" means any printable character. They can be letters, numbers, or even special symbols. Each target input string should be complex with a mix of characters, special symbols, numbers to show how the program handles each category.

USE FROM THE FOLLOWING PYTHON FUCTIONS:

def getKeyCharacter() This function requests a single character from the user and continues to ask for it until the user gets it right: this function will test to make sure the user only types one single character. 0, 2, 3 or more characters will be flagged as an error and the function will keep at the user until he types just one character.

def getString() This function requests a string from the user and continues to ask for it until the user gets it right: this function will test to make sure the user only types a string that has at least 4 characters. Make this minimum size a constant, and use that symbolic constant, not the literal (4) wherever it is needed. The acquired string will be returned as a functional return.

You must write the functions below from scratch. Do not rely on any other built-in or pre-existing functions that appear to provide any of this functionality for you.

def maskCharacter(theString, keyCharacter) This function will take both a string and a character as parameters and return a new string that has each occurrence of the key character replaced by an asterisk, '*'.

def removeCharacter(theString, keyCharacter) This function will take both a string and a character as parameters and return a new string that has each occurrence of the key character removed, but all other characters left intact.

def countKey(theString, keyCharacter) This function will take both a string and a character as parameters and return the number of key characters that appear in the string (case sensitive).

Input Errors Whenever the user makes an input error, keep at them until they get it right. Do not return from an input function until you have acquired a legal value. Test Run Requirements: Submit at least four runs. In at least one of the four runs, intentionally commit input errors to demonstrate both kinds of illegal input described above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!