In this program, we will take a string as input and find the most simultaneously repeated character in the input string.
Steps to solve the program
- Take a string as input.
- Create two variables to find the most simultaneously repeated character in a string.
- Using For loop with the range() function find whether a character is repeated in the string or not.
- If yes then, count how many times it has been repeated.
- Print the most simultaneously repeated character in a string.
#Input string
str1 = "Helllllo ffdfdas sdfsfsd sssfdddd"
max_repeat_count = 0
max_repeat_char = ''
temp = 1
for i in range(len(str1)-1):
if str1[i] == str1[i+1]:
temp = temp + 1
if temp > max_repeat_count:
max_repeat_count = temp
max_repeat_char = str1[i]
else:
temp = 1
#Printing output
print("Max repeated char :", max_repeat_char,
"\nMax repeated count :", max_repeat_count)
Output :
Max repeated char : l
Max repeated count : 5