swap_case.py 895 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
"""
This algorithm helps you to swap cases.

User will give input and then program will perform swap cases.

In other words, convert all lowercase letters to uppercase letters and vice versa.
For example:
1. Please input sentence: Algorithm.Python@89
  aLGORITHM.pYTHON@89
2. Please input sentence: github.com/mayur200
  GITHUB.COM/MAYUR200

"""


16
def swap_case(sentence: str) -> str:
17 18 19 20 21 22 23 24 25 26 27
    """
    This function will convert all lowercase letters to uppercase letters
    and vice versa.

    >>> swap_case('Algorithm.Python@89')
    'aLGORITHM.pYTHON@89'
    """
    new_string = ""
    for char in sentence:
        if char.isupper():
            new_string += char.lower()
28
        elif char.islower():
29
            new_string += char.upper()
30
        else:
31 32 33 34 35 36
            new_string += char

    return new_string


if __name__ == "__main__":
37
    print(swap_case(input("Please input sentence: ")))