Reference no: EM132162274
Define a function remainPos(...) which receives one string (st) (with letters, digits or special characters),one character (ch), and one digit (dig) (the digit will be greater or equal than 2, and clearly, since it is a digit, it will be less or equal than 9). Teh function should return a NEW STRING containing possibly several digits, separated by two dots. These digits in the returned string each are the remainder of dividing each position where the character (ch) is found by the digit (dig). Each remainder will be separated by two dots (and at the start and end of the string to be returned there should also be two dots). If the character ch is the not present in the original string, then the function should return a string containing only two dots.
For example,
s = "abc-abc-abc-abc-"
c = "a"
d = 3
giveMeRemainPos(s,c,d)
will cause the function to return the string '..0..1..2..0..' because the character "a" is in positions 0,4,8,12 in the string s, and respectively, the remainders of dividing such positions by d (= 3) will produce the values 0,1,2,0
As an example, the following code fragment:
s = "abc-abc-abc-abc-"
c = "a"
print(remainPos(s,c,3))
should produce the output:
..0..1..2..0..