TORONTO KIDS COMPUTER CLUB | Markham Saturday 9:30 Python Homework 20.05.16.
17522
post-template-default,single,single-post,postid-17522,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Markham Saturday 9:30 Python Homework 20.05.16.

19 May Markham Saturday 9:30 Python Homework 20.05.16.

Question:

You are given a string . Suppose a character ‘a’ occurs consecutively n times in the string. Replace these consecutive occurrences of the character ‘a’ with (n, ‘a’) in the string.

Input Format:  A single line of input consisting of the string .
Output Format: A single line of output consisting of the modified string.


Sample Input:
abbbcdddaa

Sample Output:
(1, 'a') (3, 'b') (1, 'c') (3, 'd') (2,'a')

Explanation:
First, the character ‘a’ occurs only once. It is replaced by (1,’a’). Then the character ‘b’ occurs three times, and it is replaced by (3,’b’) and so on. Also, note the single space after comma and between ‘) (‘.

Hint:

  • += Could join string together
  • need use for loop to read every character
  • if you do not know how to write python code please write down the logic thoughts.

No Comments

Sorry, the comment form is closed at this time.