0

Help me rectify the error, please...

Input: lnstr = int(input()) strn = str(input()) x = int(input()) y = int(input()) if strn[x].isupper(): a = strn[x].lower() else: a = strn[x].upper() if strn[y].isupper(): b = strn[y].lower() else: b = strn[y].upper() print(strn.replace(strn[x],a).replace(strn[y],b)) Output: 6 Dcoder 0 3 DcoDer Process finished. Here, only this string out of numerous test cases it doesn't work. As you see the 'D' in 0 has not been replaced with 'd'.

28th Jan 2020, 12:58 PM
Arun Bhattacharya
Arun Bhattacharya - avatar
2 odpowiedzi
+ 1
This is the question rodwynnejones : Change in Case- You will be given a single string and two positive integers denoting indices. You need to change the case of the characters at those indices.i.e change uppercase to lowercase and lowercase to uppercase. It is guaranteed that all characters in the string are alphabets. Input The first line contains N, the length of string. The next line contains a single string. Two integers, x and y, in next line separated by space. Sample Input 6 Dcoder 0 3 Output Print the string after altering the case of characters at those indices. Sample Output dcoDer Constraints- 1 <= string.length <= 40 O <= x, y <= string.length
28th Jan 2020, 5:05 PM
Arun Bhattacharya
Arun Bhattacharya - avatar
0
MIght be that "replace" will replace all "occurrences" . The string method "replace" can take a third param....count..so try 1. Please explain exactly what you are trying to do
28th Jan 2020, 1:51 PM
rodwynnejones
rodwynnejones - avatar