Using Python Write a program called CountConsecutiveChars it reads strings from
ID: 3858366 • Letter: U
Question
Using Python
Write a program called CountConsecutiveChars it reads strings from the user until the user presses enter without entering anything. it reports the number of characters that appear consecutively in the string more than once (lets call that a "run") it also prints the length of the largest run. For example if the String is: "aaxbbb", then the sum of all characters that were repeated consecutively is 5 because 'a' repeats 2 times and 'b' repeats 3 times. The largest run was 3 (the b's). as usual, you cannot use topics we haven't covered yet. For instance, in this case you cannot use indexing of strings (chapter 10). For example: str[0] is the first character of string str, str[1] is the second, etc.
Explanation / Answer
str=input("Enter the string :")
distros = { i:1 for i in str }
for i in range(len(str)-1):
if str[i] == str[i+1]:
distros[str[i]] += 1
print ("Total count of the consecutive letters are")
print(distros)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.