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
def swap_case(s):
temp = []
l = list(s)
for i in l:
j = ""
if i.islower():
j = i.upper()
elif i.isupper():
j = i.lower()
else:
temp.append(i)
temp.append(j)
r = ''.join(temp)
return r
s = input()
result = swap_case(s)
print(result)
Latest Posts
- How to convert MD (markdown) file to PDF using Pandoc on macOS Ventura 13
- How to make MD (markdown) document
- How to Install Docker Desktop on mac M1 chip (Apple chip) macOS 12 Monterey
- How to install MySQL Workbench on macOS 12 Monterey mac M1 (2021)
- How to install MySQL Community Server on macOS 12 Monterey (2021)