Asking about how to write the code

Define a function replaceCharAtPos(orig,pos) which receives two input parameters, a string (orig) and a positive integer number (pos).

If the number is a position within the string, the function should return a new string. The new string should be the original string except that instead of the original character in that position pos, it should have the position number itself (if the position number has more than 1 digit, the character should be replaced by the digit in the units part of the position number, e.g. 2 if the position number is 12).

If the number pos is not a valid position within the original string orig, the string returned should be exactly the same as the original string.

For example
replaceCharAtPos('abcd',1) should return 'a1cd'
replaceCharAtPos('abcd',10) should return 'abcd'
replaceCharAtPos('abcdefghijklmn',12) should return 'abcdefghijkl2n'

As an example, the following code fragment:
print (replaceCharAtPos("abcd",2))
should produce the output:

You are viewing a single comment. View All
JoshDaBosh (77)

@TZLALA how is it not correct