write a program to input a sentence and count the no. of repetitive letters
Answers
Answer:
what is free fire?.. and which country has most downloads of it7359042520 Tap on a clip to paste it in the text box.Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.
Answer:
This is the algorithm for the question
- Define a string or take input.
- Two loops will be used to find the duplicate characters. Outer loop will be used to select a character and initialize variable count by 1.
- Inner loop will compare the selected character with rest of the characters present in the string.
- If a match found, it increases the count by 1 and set the duplicates of selected character by '0' to mark them as visited.
- After inner loop, if count of character is greater than 1, then it has duplicates in the string.
Explanation:
string =input("Enter your string");
print("Duplicate characters in a given string: ");
#Counts each character present in the string
for i in range(0, len(string)):
count = 1;
for j in range(i+1, len(string)):
if(string[i] == string[j] and string[i] != ' '):
count = count + 1;
#Set string[j] to 0 to avoid printing visited character
string = string[:j] + '0' + string[j+1:];
#A character is considered as duplicate if count is greater than 1
if(count > 1 and string[i] != '0'):
print(string[i]);