Count Consecutive Substrings in Python Assignment Answers
Your question:

Q-2 [30 pts] You need to write a function consecutive(refstring) that takes a string refstring as a parameter and returns the number of disjoint substrings with consecutive characters. A substring with 2 or more consecutive characters will be counted once. For example: consecutive('settle') will return 1 consecutive('printing') will return 0 consecutive('Yessss. Really ? Reaaaaalllly?') will return return 4
Assignment Help Answers with Step-by-Step Explanation:
for i in range(1, len(refstring)):
current_char = refstring[i]
else:
# Check if the current substring has two or more consecutive characters
if current_count >= 2:
count += 1
print(consecutive('Yessss. Really ? Reaaaaalllly?')) # Output: 4


