Toggle Case
Python
Easy
3 views
Problem Description
A string s is provided. Convert lowercase to uppercase and uppercase to lowercase. Other characters keep same. Output final string.
Output Format
One line toggled.
Official Solution
import sys
s=sys.stdin.read()
if s is None: sys.exit(0)
if s.endswith('\
'):
s=s[:-1]
out=[]
for ch in s:
o=ord(ch)
if 65<=o<=90:
out.append(chr(o+32))
elif 97<=o<=122:
out.append(chr(o-32))
else:
out.append(ch)
sys.stdout.write(''.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!