Here's the instruction:
Define a function named giveMeRemainPos(...) which receives one string (st) and one character (ch) and returns a new string containing the remainder of dividing by 3 the position where the character is found, each remainder 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 = "abcdabcdabcdabcd" c = "a" giveMeRemainPos(s,c)
will cause the function to return the string '..0..1..2..0..' because "a" is in positions 0,4,8,12 and respectively, the remainders of dividing such positions by 3 will produce the values 0,1,2,0.
def giveMeRemainPos(s,c):
res=".."
for i in range(len(s)):
if (s[i]==c):
res=res+str(i%3)+".."
return res
s = "abcdabcdabcdabcd"
c = "a"
giveMeRemainPos(s,c)
The output should be this:
..0..1..2..0..
But my code returns me nothing at all. Even if I return a random string likereturn "astring".
Aucun commentaire:
Enregistrer un commentaire