Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function: Description: Given a string (st) and a character (ch) as input, this f

ID: 3545796 • Letter: F

Question

Function:

Description:

Given a string (st) and a character (ch) as input, this function should return a new string.

The returned string should have the word 'No' if the character is not found in the original string, neither in lower case nor in upper case. On the other hand, if the character is in the original string, either in lower or upper case, the function should return a string containing the word 'Yes', followed by (with no space in between) three dots '...' and followed by all the positions where the character is in the original string, in the same order as they are found in the string. The positions should be in the resulting string with one space in between, and there will be one space after the last number (which is the last position where the character is found)


For example:

whichPositions('abcabcABC','$') should return 'No'

whichPositions('abcabcABC','a') should return 'Yes...0 3 6 '


An example:

Explanation / Answer

def whichPositionsRev (st, ch):

st = st.lower()

ch = ch.lower()

idx = st.find(ch)

if (idx < 0):

return 'No'

#endif

s = str(idx) + ' '

np = st.find(ch, idx + 1)

while (np >= 0):

s = str(np) + ' ' + s

idx = np

np = st.find(ch, idx + 1)

#end while

return 'Yes...' + s