For Example:
- 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
- A single line containing a string s.
- 0 < len(s) <= 1000
Sample Input:
HackerRank.com presents "Pythonist 2".
Sample Output:hACKERrANK.COM PRESENTS "pYTHONIST 2".
def swap_case(s):
ans=""
for i in s:
if i.isupper():
ans+=i.lower()
elif i.islower():
ans+=i.upper()
else:
ans+=i
return ans
if __name__ == '__main__':
s = input()
result = swap_case(s)
print(result)
Disclaimer: The problem statement is given by hackerrank.com but the solution is generated by the Geek4Tutorial admin. If there is any concern regarding this post or website, please contact us using the contact form. Thank you!
No comments:
Post a Comment