sWAP cASE in Python - HackerRank Solution | Hackerrank Solution

 Problem Statement :

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.



For Example:

         Www.HackerRankSolution.in → wWW.hACKERrANKsOLUTION.IN

         Pythonist 2 → pYTHONIST 2


Input Format:

         A single line containing a string S.


Constraints:

         0<len(S)<=1000


Sample Input 0

HackerRank.com presents "Pythonist 2".


Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2"


Code:

def swap_case(s):

    # sWAP cASE in Python - HackerRank Solution START
    Output = '';
    for char in s:
        if(char.isupper()==True):
            Output += (char.lower());
        elif(char.islower()==True):
            Output += (char.upper());
        else:
            Output += char;
    return Output;
    # sWAP cASE in Python - HackerRank Solution END

if __name__ == '__main__':
    s = input()
    result = swap_case(s)
    print(result)

Ignore: Hacker Rank Solution Hacker Rank Python solution Hacker Rank Java Hacker Rank C++

No comments:

Powered by Blogger.