Hanwool Codes RSS Tag Admin Write Guestbook
2023-02-03 03:44:47

sWAP cASE | HackerRank

 

sWAP cASE | HackerRank

Swap the letter cases of a given string.

www.hackerrank.com

 

Goal

 

You are given a string and your task is to swap cases. 

In other words, convert all lowercase letters to uppercase letters and vice versa.

 

Solution

 

You can read one character in string and swap cases and return new string.

 

# sWAP cASE

def swap_case(s):
    
    new_s = ""
    
    for c in s:
        if c.isupper():
            new_s += c.lower()
            
        else:
            new_s += c.upper()
            
    return new_s


if __name__ == '__main__':
    s = input()
    result = swap_case(s)
    print(result)
Hanwool Codes. Designed by 코딩재개발.