Given a string, toggle the case of each character in the given string.

Posted on | Wednesday, 17 May 2023 | No Comments

 Given a string, toggle the case of each character in the given string.

Input Format

Input contains a string S, consisting of lowercase and uppercase characters.

Constraints

1 <= len(S) <= 100

Output Format

Print the toggled string.

Sample Input 0

abdBd

Sample Output 0

ABDbD
string = input()

string1 = ''

for i in range(len(string)):
    if(string[i] >= 'a' and string[i] <= 'z'): 
        string1 = string1 + chr((ord(string[i]) - 32)) 
    elif(string[i] >= 'A' and string[i] <= 'Z'):
        string1 = string1 + chr((ord(string[i]) + 32))
    else:
        string1 = string1 + string[i]
 

print(string1)

Comments

Leave a Reply

Search

Followers