Python program to find the matched characters in a given string

Here, we are going to execute a python program in which we need to analyze the strings and locate the coordinated characters with the given string and client entered a string.

In this article, we are going to execute a portion of the highlights of if explanation to check the characters present inside the entered string.

The client is approached to enter a string with numerous characters according to the client’s decision and the code will check whether the string has a portion of the recorded characters inside in it.

On the off chance that the string has all characters coordinated with the recorded one, at that point it prints “Totally In” and else “Not In” with the number of characters coordinated.

So here is the code:

secretword = str(input("Enter a string: "))
lettersGuessed = ['a', 'e', 'i', 'k', 'p', 'r', 's','l']
flag = 0

for i in secretword:
        if i in lettersGuessed:
             flag+=1
if len(secretword) == flag:
    print("Completely In")
else:
    print("Not In")

print(flag, 'matches')    

Output:

First run:
Enter a string: aeiprsl
Completely In
7 matches

Second run:
Enter a string: xyz
Not In
0 matches

Leave a Comment

error: Alert: Content is protected!!