sWAP cASE in Python HackerRank Solution

Hello Programmers, In this post, you will know how to solve the sWAP cASE in Python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

Ezoicreport this adsWAP cASE in Python HackerRank Solution
sWAP cASE in Python HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

sWAP cASE in Python Hacker Rank Solution

Ezoicreport this adproblem

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  

Function Description

Complete the swap_case function in the editor below.

swap_case has the following parameters:

  • string s: the string to modify

Returns

  • string: the modified string

Input Format

A single line containing a string .

Constraints

0 <= len(s) <=1000

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2".

sWAP cASE in Python Hacker Rank Solution

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)

Disclaimer: The above Problem (sWAP cASE in Python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: String Split and Join in Python HackerRank Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad