Python Exercises: Two strings contain three letters at the same index
Count matches of three letters at same index.
Write a Python program that takes two strings. Count the number of times each string contains the same three letters at the same index.
Sample Data:
(“Red RedGreen”) -> 1
(“Red White Red White) -> 7
(“Red White White Red”) -> 0
Sample Solution-1:
Python Code:
Sample Output:
Original strings: Red RedGreen Check said two strings contain three letters at the same index: 1 Original strings: Red White Red White Check said two strings contain three letters at the same index: 7 Original strings: Red White White Red Check said two strings contain three letters at the same index: 0
Flowchart:
Sample Solution-2:
Python Code:
Sample Output:
Original strings: Red RedGreen Check said two strings contain three letters at the same index: 1 Original strings: Red White Red White Check said two strings contain three letters at the same index: 7 Original strings: Red White White Red Check said two strings contain three letters at the same index: 0
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program that takes two strings and counts the number of positions where both strings have the same three-letter sequence.
- Write a Python program to slide a window of three characters over two strings and count matching triplets at the same indices.
- Write a Python program to implement a function that returns the count of matching three-letter segments from two equal-length strings.
- Write a Python program to use list comprehension and slicing to compare triplets from two strings and tally the matches.
Go to:
Previous Python Exercise: Replace repeated characters with single letters.
Next Python Exercise: Hash elements.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.