sWAP cASE in Python - Hacker Rank Solution

Hello coders, today we will be solving sWAP cASE Hacker Rank Solution in Python. You are given a string and your task is to swap cases. In other words

Hello coders, today we will be solving sWAP cASE Hacker Rank Solution in Python.

sWAP cASE in Python - Hacker Rank Solution

Problem

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.HackerRank.com  wWW.hACKERrANK.COM
Pythonist 2  pYTHONIST 2

Input Format 

A single line containing a string S.

Constraints

0 <= len(S) <= 1000

Output Format 

Print the modified string S.

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2".

Solution - sWAP cASE in Python - Hacker Rank Solution 

def swap_case(s):
    num = ""
    for let in s:
        if let.isupper() == True:
            num+=(let.lower())
        else:
            num+=(let.upper())
    return num

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

Disclaimer: The above Problem (sWAP cAse) is generated by Hacker Rank but the Solution is provided by Sloth Coders.

Happy Coding !!

A Sloth Who loves to Code

Also Read:

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment