Question: In Python!!! Write a program that compares two strings given as input. Output the number of characters that match in each string position. The output
In Python!!!
Write a program that compares two strings given as input. Output the number of characters that match in each string position. The output should use the correct verb match vs matches according to the character count.
Step :
Get the two strings as input no prompt
Use an ifelse statement to determine which is the shortest string this is needed for our for loop to ensure we don't get an "out of bounds" error.
Step :
Use a for loop and the range of the shortest string to compare each character in the strings to see if they match. Remember, that strings are indexed as etc. So string gives the first letter. If there is a match, increment the count variable. We are finding this so we can have the correct verb tense for our output
Step :
Use an ifelse statement and the count variable to decide which phrase should be output match vs matches Remember, if there is only one match, it is singular. Otherwise it is plural.
Inputs and Outputs
Ex: If the input is:
crash
crush
the output is:
characters match
Ex: If the input is:
cat
catnip
the output is:
characters match
Ex: If the input is:
mall
saw
the output is:
character matches
Ex: If the input is:
apple
orange
the output is:
characters match
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
