sWAP cASE | HackerRank
Swap the letter cases of a given string.
www.hackerrank.com
Goal
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.
Solution
You can read one character in string and swap cases and return new string.
# sWAP cASE
def swap_case(s):
new_s = ""
for c in s:
if c.isupper():
new_s += c.lower()
else:
new_s += c.upper()
return new_s
if __name__ == '__main__':
s = input()
result = swap_case(s)
print(result)
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
[Python] HackerRank - What's Your Name? (0) | 2023.02.11 |
---|---|
[Python] HackerRank - String Split and Join (0) | 2023.02.07 |
[Python] HackerRank - Lists (0) | 2023.02.02 |
[Python] HackerRank - Finding the percentage (0) | 2023.02.01 |
[Python] HackerRank - Nested Lists (0) | 2023.01.31 |