Algorithm


Problem Name: Python - sWAP cASE

Problem Link: https://www.hackerrank.com/challenges/swap-case/problem?isFullScreen=true

In this HackerRank Functions in PYTHON problem solution,

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 s.

Constraints

0 <= len(s) =< 1000

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2".

 

 

 

Code Examples

#1 Code Example with Python Programming

Code - Python Programming


def swap_case(s):
    solution =''
    for element in s:
        if element.isupper():
            solution=solution+element.lower()
        else:
            solution=solution+element.upper()
    return solution



if __name__ == '__main__':
    s = raw_input()
    result = swap_case(s)
    print result
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
[Solved] Tuples in PYTHON solution in Hackerrank
Next
[Solved] String Split and Join in PYTHON solution in Hackerrank