As a newbie programmer

Change in Case @ Docder

Docder icon

Problem: 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.
Output: Print the string after altering the case of characters at those indices
Constraints: 1 ≤ string.length ≤ 40
0 ≤ x,y ≤ string.length
Sample Input: 6
Dcoder
0 3
Sample Output:
dcoDer

n = int(input())
s = list(input())
x, y = map(int, input().split())
for i in (x, y):
  s[i] = s[i].lower() if s[i].isupper() else s[i].upper()
print(''.join(s))

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?