python - My program is working, but I don't want overlapping of adjacent pairs. For e.g; if i have 'aaa', the number of pairs should be only 1, not 2 -
def pairs(message, num_pair, i): if == len(message) - 1: return("number of pairs:", num_pair) else: if message[i]==message[i+1]: return pairs(message, num_pair+1, i+1) else: return pairs(message, num_pair, i+1) def main(): message = input("enter message: \n") num_pair = 0 = 0 message, p = pairs(message, num_pair, i) print (message, p) main()
enter message: aaaa number of pairs: 3
however, output should 2, when finish comparing 2 characters , find same, should move other character second one.
after detecting pair skip completely. means instead of advancing 1 char advance index 2.
Comments
Post a Comment