sWAP cASE in Python | HackerRank Solution

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

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 in Python) is generated by Hacker Rank but the Solution is provided by CodingBroz. This tutorial is only for Educational and Learning purposes.

Leave a Comment

Your email address will not be published.